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:


Returns true/false

Valid: 11.5, 1e4

Invalid: “2.5”, 4, 0


Numeric Validation:


Returns true/false

Valid: 40, 1e4, 1550, 9.5

Invalid: “2.5”


String Validation:


Returns true/false

Valid: ‘abc’, “abc”

Invalid: 11.5, 23, true

Posted in PHP

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s