Email validation expression \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
allows empty spaces, but otherwise works perfectly.
It does not fail the following email address:
john doe@hp.edu
How can I restrict this to not allow whitespaces?
Email validation expression \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
allows empty spaces, but otherwise works perfectly.
It does not fail the following email address:
john doe@hp.edu
How can I restrict this to not allow whitespaces?
Some APIs have functionality to match on the entire string, where-as with others it would always search anywhere in the string.
If it's the latter case, it won't fail because a substring, specifically doe@hp.edu
, matches the pattern.
To fix this, you could either check if the API you're using has a function to match on the entire string, or you could add ^
to the start and $
to the end of your pattern, indicating the start and end of string / line respectively.
^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$