the program I'm using has its own email validation built in and it only accept emails where the last group of characters after the LAST period is 2 or more. I have this regex statement so far:
/^[^@]+@[^@]+\\.[^@]+$/i
This is acceptable for what I'm trying to do, not trying to be super fancy here. Just want to check:
I'm just not sure how to test for the LAST . as opposed to ANY . after the @ sign.
Any help?
You can impose this check at the beginning with a positive look-ahead:
/^(?=.*\.[^.]{2,}$)[^@]+@[^@]+\.[^@]+$/i
^^^^^^^^^^^^^^^^
See demo
The (?=.*\.[^.]{2,}$) look-ahead will find the last . and then will try to match 2 or more characters other than a dot before the end of string. If there is fewer (just 1) the match will be failed (there will be no match).
UPDATE
As you might be unable to use the regex having ^/$ anchors in other places than start/end of string, here is another solution:
^[^@]+@[^@]+\.[^@.]{2,}$
See demo
Regex breakdown:
^ - start of string[^@]+ - 1 or more characters other than @@ - literal @ symbol[^@]+ - 1 or more characters other than @ as many as possible (thus, no [email protected] is possible)\. - a literal dot[^@.]{2,} - 2 or more characters other than @ and . up to...$ - end of stringIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With