PHP Validate Email Address, Phone & URL

Validate email using PHP grep functions

function isValidEmail($email){
    return eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $email);
}

Validate phone numbers

$phone = preg_replace('/[^0-9]/', '', $phone); # remove non-numbers
// check if > 9 digits
if (strlen($phone)>9) {
echo 'Valid';
}

Validate URL links

if(preg_match("/^(http(s?)://|ftp://{1})((w+.){1,})w{2,}$/i", $url)){
#Is a valid URL
} else {
#Is not a valid URL
}

You may also like...

Leave a Reply