Email Validation Regular Expressions Php

Regular expressions are nothing more than a sequence or pattern of characters itself. They provide the foundation for pattern-matching functionality.
With The Help Of Regular Expression we can validation check in email address.

Email Address Validation
Ereg(“^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9]+”,$my_string)
String Pattern Parts:
Part 1:
^[a-zA-Z0-9._%+-]+
Part 2:
@
Part 3:
[a-zA-Z0-9.-]+
Part 4:
\.
Part 5:
[a-zA-Z0-9]+
Description
• Ereg php built-in function is used to check the email validation code with two arguments:
1. Validation code
2. String containing intended email address
• ^[a-zA-Z0-9._%+-]+
^
The “caret” sign is used to insist the sub string to appear at the start of the main string according to the pattern specified inside the brackets[ ].
[a-zA-Z0-9._%+-]
a-z:To check that substring may contain small alphabets.
A-Z:To check that substring may contain large alphabets.
0-9:To check that substring may contain numeric characters.
._%+- : To check that substring may contain dot(.) , underscore(_) , percentage(%), plus(+) or minus(-).
+
Plus sign determines that the preceding pattern may repeat for at least one or more times.
• @
Sign @ must occur after the above specified pattern string.

• [a-zA-Z0-9.-]+
String pattern to appear after the @ sign.
[a-zA-Z0-9.-]
a-z:To check that substring may contain small alphabets.
A-Z:To check that substring may contain large alphabets.
0-9:To check that substring may contain numeric characters.
.- : To check that substring may contain dot(.) or minus(-).
+
Plus sign determines that the preceding pattern may repeat for at least one or more times.
• \.
\.
Back slash(\) and dot(.) specify that the
dot(.) must appear after the preceding string .
• [a-zA-Z0-9]+
String pattern to appear after the dot(.) sign.
[a-zA-Z0-9]
a-z:To check that substring may contain small alphabets.
A-Z:To check that substring may contain large alphabets.
0-9:To check that substring may contain numeric characters.
+
Plus sign determines that the preceding pattern may repeat for at least one or more times.

Examples
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9]+
1)
Email Address = nadeem12@gmail.com
Description:
In the above email address“nadeem12” is “valid” according to the part1 of the string pattern , @ is also appearing exactly after the first substring ,”gmail” is also valid according to the part3 of string pattern , “.” is also exist after substring by part3 pattern and “com” also appearing as substring matching with part5 pattern.
Conclusion:
Specified email address is a valid one.

2)
Email Address = nadeem12@gmail.com
Description:
In the above email address“nadeem12” is “valid” according to the part1 of the string pattern , @ is also appearing exactly after the first substring ,”gmail” is also valid according to the part3 of string pattern , “.” is also exist after substring by part3 pattern and “com” also appearing as substring matching with part5 pattern.
Conclusion:
Specified email address is a valid one.

Was this article helpful?

Related Articles