Official documentation : Click here
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+
- Mobile number
- Password
- Numeric password only
- Special password only
- Required
- Check Length
- Alphabet Only
- Alphanumeric Only
- Numeric Only
- Alphanumericwithspace Only
- Numericwithspace Only
- Date
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
require " BasicValidation.php"
This method check whether data is alphanumeric only or not
Return : true or false
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 |
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
This method check whether data is numeric only or not
Return : true or false
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 |
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
This method check whether data is alphabetic only or not
Return : true or false
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 |
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
This method check whether data is alphanumeric only or not and also allow space
Return : true or false
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 |
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
This method check whether data is numeric only or not and also allow space
Return : true or false
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 |
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
This method check whether data is alphabet only or not and also allow space
Return : true or false
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 |
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
This method check whether data is present or not
Return : true or false
Key | Required | Type | Default | Description |
---|---|---|---|---|
$data | true | String | NULL | User date to be validate |
$space | false | bool | false | space allow or not |
if($obj->required($data,false)){ echo "success"; } else{ echo "failed"; }
input : $data = "validation" output : success
input : $data = " " output : failed
This method check whether data is in specific length
Return : true or false
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 |
if($obj->length($data,0,10)){ echo "success"; } else{ echo "failed"; }
input : $data = "validation" output : success
input : $data = "validation1234" output : failed
This method check whether data is in email format or not
Return : true or false
Key | Required | Type | Default | Description |
---|---|---|---|---|
$data | true | String | NULL | User date to be validate |
if($obj->email($data)){ echo "success"; } else{ echo "failed"; }
input : $data = "[email protected]" output : success
input : $data = "validation1234" output : failed
This method check whether data is in url format or not
Return : true or false
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 |
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.
This method check whether data is in ip format or not i.e ipv4 or ipv6
Return : true or false
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 |
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
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
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.
This method check whether date is in between range or not
Return : true or false
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 |
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
This method check whether password format correct or not
Return : true or false
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
if($obj->password($data,"alphanumeric",true,0,20)){ echo "success"; } else{ echo "failed"; }
input : $data = "validation1234" output : success
input : $data = "validation1234@" output : failed
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.
Mobile number validation
if($obj->numericOnly($data,true,0,10)){ echo "success"; } else{ echo "failed"; }
input : $data = "1234567890" output : success
input : $data = "1234567" output : failed
© 2017, Knicklab, All rights reserved