Reputation:
I am using .NET for my email validation:
[Display(Name = "Email address")]
[Required(ErrorMessage = "The email address is required")]
[EmailAddress(ErrorMessage = "Invalid Email Address")]
But if I copy paste an email address like [email protected]
( notice the empty space at the end of .com it says it is invalid.
How can I tell it to ignore that empty space for validation?
I couldn't type empty space in SO editor, imagine there are empty spaces after .com
Upvotes: 6
Views: 2779
Reputation: 993
You could use the regex validation Attribute and use some Regex that allows for spaces at the beginning and end. An example is given below :
^ *([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,6}) *$
However, this regex is a sample only and I recommend you visit This site or the SO post mentioned in the comments below to find a regex that is acceptable to your needs and then use the [Space]*
at either end to allow unlimited spaces
Upvotes: 6