Php Regular Expressions and Validations

regular.thumbnail

Php regular expression to validate an email address

$email = 'sajithmr2005@yahoo.com';
if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",
$email))
{
echo 'valid email' ;
}

?>

//Regular Expression for Validate a number

$mobile = '9846831106';

if ( ereg('^[[:digit:]]+$', $mobile) )

{

echo 'valid number';

}

?>

Regular Expression for Removing non-alphabetic characters from a string or a Filename.

$newFilename = preg_replace(“/[^a-zA-Z0-9s.]/”, “”, $newFilename);

0 Comments

No comments yet.

Leave a Reply

More in php (86 of 101 articles)


Before starting php tutorials >>> Hai friends, Before you starting the php programming, one thing i would like to ...