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
}

Php Remove Non-Alphanumeric Characters

How to strip all symbols and numbers from a string of alphanumeric text. This php code will help you delete, remove, strip and erase any non-alphanumeric characters, and then return the data without the unwanted characters. Continue Reading »