I m just learning regular expression matching using javascript, and have a doubt regarding the scenario described below.
I’m trying to validate email, with condition below:
Format should be
xxx@yyy.zzzwhere
A) “xxx”, “yyy” and “zzz” parts
can take values only between lowercase a and z
B) The length of zzz,
yyy and xxx parts are arbitrary (should be minimum one though)
Now I understand I can build the regex like this:
EDIT:
CORRECTED REG EXP
/[a-z]+@[a-z]+\.[a-z]+/
and the above would evaluate a string like “aaa@aaa.aaa” as true.
But my concern is, in the above expression if i provide "a999@aaa.aaa", again it would evaluate as true. Now, if i modify the reg ex as **/[a-z]{1,}@[a-z]+\.[a-z]+/** even then it would evaluate "a999@aaa.aaa" as true because of the presence of “a” as the first character.
So, I would like to know how to match the first part “xxx” in the email "xxx@yyy.zzz" in a way that it checks the entire string from first char till it reaches the @ symbol with the condition that it should take only a to z as valid value.
In other words, the regex should not mind the length of the username part of email, and irrespective of the number of chars entered, it should test it based on the specified regex condition, and it should test it for the set of chars from index 1 to index of @.
Your regular expression will not show
a999@aaa.aaato be a match. It will, however, show that9999a@aaa.aaa9999is a match. The regular expression markers you’re missing are^for the start of string and$for end of string. This is what you’re looking for:You can test this expression out over on this online validator: http://tools.netshiftmedia.com/regexlibrary/#