Skip to content

shinde-sagar/php-formvalidation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Official documentation : Click here

FormValidation 1.0

BY KNICKLAB.

Introduction


Form validation has been an important subject. To validate user input using PHP require more coding skills. Knicklab present ‘Form validation 1.0’. These ‘Form validation 1.0’ library make it easy to validate user input at server side using PHP.

These package requires PHP 5.4+ 

Features


  • Email
  • Mobile number
  • Password
  • Numeric password only
  • Special password only
  • Required
  • Check Length
  • Alphabet Only
  • Alphanumeric Only
  • Numeric Only
  • Alphanumericwithspace Only
  • Numericwithspace Only
  • Date

Installation


After Download package, Copy BasicValidation_interface.php and BasicValidation.php to your project folder. Type require BasicValidation.php at the top of your project .php file

Example

require " BasicValidation.php"


alphanumericOnly()


This method check whether data is alphanumeric only or not

Return : true or false

Arguments

Key Required Type Default Description
$data true String NULL User date to be validate
$required false Bool false User data to be required or not
$min false int NULL Min user data string length
$max false int NULL Max user data string length

Example

if($obj->alphanumericOnly($data,true,0,20)){
    echo "success";
}
else{
    echo "failed";
}
input : $data = "validation1234"
output : success
input : $data = "validation 234@"
output : failed

Note : These method allow only alphabet and numeric value if any special character is there or any space then function will return false


numericOnly()


This method check whether data is numeric only or not

Return : true or false

Arguments

Key Required Type Default Description
$data true String NULL User date to be validate
$required false Bool false User data to be required or not
$min false int NULL Min user data string length
$max false int NULL Max user data string length

Example

if($obj->numericOnly($data,true,0,10)){
    echo "success";
}
else{
    echo "failed";
}
input : $data = "12345"
output : success
input : $data = "validation1234"
output : failed

Note : These method allow only numeric value if any alphabet or special character is there or any space then function wil return false


alphabetOnly()


This method check whether data is alphabetic only or not

Return : true or false

Arguments

Key Required Type Default Description
$data true String NULL User date to be validate
$required false Bool false User data to be required or not
$min false int NULL Min user data string length
$max false int NULL Max user data string length

Example

if($obj->alphabetOnly($data,true,0,10)){
    echo "success";
}
else{
    echo "failed";
}
input : $data = "validation"
output : success
input : $data = "validation 234@"
output : failed

Note : These method allow only alphabetic value if any numeric or special character is there or any space then function will return false


alphanumericOnlywithspace()


This method check whether data is alphanumeric only or not and also allow space

Return : true or false

Arguments

Key Required Type Default Description
$data true String NULL User date to be validate
$required false Bool false User data to be required or not
$min false int NULL Min user data string length
$max false int NULL Max user data string length

Example

if($obj->alphanumericOnlywithspace($data,true,0,20)){
    echo "success";
}
else{
    echo "failed";
}
input : $data = "validation 245"
output : success
input : $data = "validation1234@"
output : failed

Note : These method allow alphanumeric value as well as space. if any special character is there, then function will return false


numericOnlywithspace()


This method check whether data is numeric only or not and also allow space

Return : true or false

Arguments

Key Required Type Default Description
$data true String NULL User date to be validate
$required false Bool false User data to be required or not
$min false int NULL Min user data string length
$max false int NULL Max user data string length

Example

if($obj->numericOnlywithspace($data,true,0,10)){
    echo "success";
}
else{
    echo "failed";
}
input : $data = "124 5"
output : success
input : $data = "validation 1234"
output : failed

Note : These method allow numeric value as well as space. if any special character is there, then function will return false


alphabetOnlywithspace()


This method check whether data is alphabet only or not and also allow space

Return : true or false

Arguments

Key Required Type Default Description
$data true String NULL User date to be validate
$required false Bool false User data to be required or not
$min false int NULL Min user data string length
$max false int NULL Max user data string length

Example

if($obj->alphabetOnlywithspace($data,true,0,20)){
    echo "success";
}
else{
    echo "failed";
}
input : $data = "valida tion"
output : success
input : $data = "valida tion1"
output : failed

Note : These method allow alphabetic value as well as space. if any special character is there, then function will return false


required()


This method check whether data is present or not

Return : true or false

Arguments

Key Required Type Default Description
$data true String NULL User date to be validate
$space false bool false space allow or not

Example

if($obj->required($data,false)){
    echo "success";
}
else{
    echo "failed";
}
input : $data = "validation"
output : success
input : $data = "  "
output : failed


length()


This method check whether data is in specific length

Return : true or false

Arguments

Key Required Type Default Description
$data true String NULL User date to be validate
$min false int false Min user data string length
$max false int false Max user data string length

Example

if($obj->length($data,0,10)){
    echo "success";
}
else{
    echo "failed";
}
input : $data = "validation"
output : success
input : $data = "validation1234"
output : failed


email()


This method check whether data is in email format or not

Return : true or false

Arguments

Key Required Type Default Description
$data true String NULL User date to be validate

Example

if($obj->email($data)){
    echo "success";
}
else{
    echo "failed";
}
input : $data = "[email protected]"
output : success
input : $data = "validation1234"
output : failed


url()


This method check whether data is in url format or not

Return : true or false

Arguments

Key Required Type Default Description
$data true String NULL User date to be validate
$min false int false Min user data string length
$max false int false Max user data string length

Example

if($obj->url($data,0,10)){
    echo "success";
}
else{
    echo "failed";
}
input : $data = "http://validation"
output : success
input : $data = "validation1234"
output : failed

Note : These method allow only url.


ip()


This method check whether data is in ip format or not i.e ipv4 or ipv6

Return : true or false

Arguments

Key Required Type Default Description
$data true String NULL User date to be validate
$type false string NULL is used for ip type i.e ipv4 or ipv6

Example

if($obj->ip($data)){
    echo "success";
}
else{
    echo "failed";
}
input : $data = "172.22.26.78"
output : success
input : $data = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
output : success

Example2

if($obj->ip($data,"ipv4")){
    echo "success";
}
else{
    echo "failed";
}
input : $data = "172.22.26.78"
output : success
input : $data = "172.22.26.258"
output : failed

Example3

if($obj->ip($data,"ipv6")){
    echo "success";
}
else{
    echo "failed";
}
input : $data = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
output : success
input : $data = "172.22.26.258"
output : failed

Note : If you want to allow only ipv4, then pass second argument as "ipv4" or if you want to allow only ipv6, then pass second argument as "ipv6". If you want to allow both then don't pass second argument.


date()


This method check whether date is in between range or not

Return : true or false

Arguments

Key Required Type Default Description
$data true String NULL User date to be validate
$between true array NULL Two date min and max for range checking

Example

if($obj->date($data,["12-05-2012","12-12-2018"])){
    echo "success";
}
else{
    echo "failed";
}
input : $data = "18-05-2012"
output : success
input : $data = "12-05-1996"
output : failed


password()


This method check whether password format correct or not

Return : true or false

Arguments

Key Required Type Default Description
$data true String NULL User date to be validate
$type true String NULL password type given below :
$required false bool false Min user data string length
$min false int 0 Min user data string length
$max false int 20 Max user data string length

type :

  • alphanumeric : alphanumeric password allow only
  • numeric : numeric password allow only
  • alphabet : alphabet password allow only
  • special : 1 Upper letter,1 lower letter,1 numeric and 1 special character or more

Example

if($obj->password($data,"alphanumeric",true,0,20)){
    echo "success";
}
else{
    echo "failed";
}
input : $data = "validation1234"
output : success
input : $data = "validation1234@"
output : failed

Example2

if($obj->password($data,"special",true,0,20)){
    echo "success";
}
else{
    echo "failed";
}
input : $data = "Validation1234@"
output : success
input : $data = "validation123"
output : failed

Note : These method validate password.


Extra pratice problem


Mobile number validation

Example

if($obj->numericOnly($data,true,0,10)){
    echo "success";
}
else{
    echo "failed";
}
input : $data = "1234567890"
output : success
input : $data = "1234567"
output : failed


Presented By knicklab.com

© 2017, Knicklab, All rights reserved

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages