Some Useful Regex

Mail-id verification:

/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/

Though both can be used in PHP and JS but there is another method to verify an email-id in PHP, by using the below code

if(!filter_var($email, FILTER_VALIDATE_EMAIL))

FILTER_VALIDATE_EMAIL is a predefined filter in PHP.
Name Verification:

/^[A-Za-z .'-]+$/

Phone Verification:

/^[0-9 -]+$/

Removing all spaces:

$pattern = '/\s+/';
$replace = "";
$string = preg_replace($pattern,$replace,$string);

 

Leave a Reply