Email validator to ignore empty space

I use .NET to check my email:

    [Display(Name = "Email address")]
    [Required(ErrorMessage = "The email address is required")]
    [EmailAddress(ErrorMessage = "Invalid Email Address")]

But if I copy paste the email address, for example bc@good.com(pay attention to the empty space at the end of .com, it says that it is incorrect. How can I say to ignore this empty space for verification?

I could not enter empty space in the SO-editor, imagine that there are spaces after it. com

+4
source share
1 answer

You can use the regex validation attribute and use some Regex that allows spaces at the beginning and end. An example is given below:

^ *([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,6}) *$

, , SO, , , , [Space]* ,

+6

Source: https://habr.com/ru/post/1650042/


All Articles