I am using a regular expression to validate an email address with example@gmail.com or example@google.net.
This is my regex:
/^([A-za-z0-9_\.-]+\@[\gmail\.-]+\.[com\.]{2,6})$/
However, it is wrong, somebody help me, thanks very much.
I am using a regular expression to validate an email address with example@gmail.com or example@google.net.
This is my regex:
/^([A-za-z0-9_\.-]+\@[\gmail\.-]+\.[com\.]{2,6})$/
However, it is wrong, somebody help me, thanks very much.
This regex will match both xxx@gmail.com and xxx@google.net
^[A-Za-z0-9_.\-]+@(?:gmail\.com|google\.net)$
You'll notice that the 2 domains are put in a non-capturing group, separated by a pipe (OR)
Do note also that something like [com]
in a regex is not to match the word "com", but to match the characters "c","o","m".