Regular expression for validating email in php
I think it’s a bit of an overkill for most use cases.
For example, matches nothing in "cndy", the 'a' in "candy," the first two a's in "caandy," and the first three a's in "caaaaaaandy" Notice that when matching "caaaaaaandy", the match is "aaa", even though the original string had more a's in it.Now consider using Mailbox Validator’s email validation service.It not only validates the email address syntax but it also does verifications with the mail servers to check if that email address actually exists.It is better to use regex, at least it is better for your coding skills, as such knowledge will carry over to other languages that can’t use the .NET Framework to find a badly formatted email address.This index page have both html code and java script code , when you will execute this page you will get a form on screen asking for entering the email id and message and then submit form by pressing submit button.
and java script code will validate the user for the cases like “unfilled form field” or”filled incorrect text” , in this script email address field is validating by regular expression(regex) which is quite strong validation type.
The thing is that there are so many combinations of characters that are considered valid for an email address which makes for a monumental task when trying to come up with a regular expression or a series of regular expressions to cover all the cases.
Suffice to say that unless you have studied the RFC standards thoroughly, you would be surprised to find out that the following characters =\/ are considered valid characters in an email address.
[email protected] – “.a” is not a valid tld, last tld must contains at least two characters 4. mkyong()*@– email’s is only allow character, digit, underscore and dash 8.
[email protected]– email’s first character can not start with dot “.” 7.
See the special character meanings below for an explanation of the above.