Php Regular Expressions and Validations

regular.thumbnail

Php regular expression to validate an email address

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$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 (89 of 104 articles)


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