PHP Validations


Email Validation:

if(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
echo “E-mail is not valid”;
}

 

Integer Validation:

is_int($var)  or is_integer($var)

Returns true/false

Valid: 2, 4, 10

Invalid: “2”, 2.5

 

Float Validation:

is_float($var)

Returns true/false

Valid: 11.5, 1e4

Invalid: “2.5”, 4, 0

 

Numeric Validation:

is_numeric($var)

Returns true/false

Valid: 40, 1e4, 1550, 9.5

Invalid: “2.5”

 

String Validation:

is_string($var)

Returns true/false

Valid: ‘abc’, “abc”

Invalid: 11.5, 23, true

Advertisements