Saw this code for regular expression validation of an email address via data annotations.
I Can't work out the purpose of the double backslash.
To me it's saying there must be a backslash in the email - but I know that this isn't what it is doing!!!
[RegularExpression(".+\\@.+\\..+", ErrorMessage="Please enter a valid email")]
The backslash is an escape character both in C# and in a regex. So, in C#, "\\" equals to a single backslash. The resulting backslash is then used to escape the ., which is a metacharacter and therefore must be escaped. I don't know why the @ is escaped however.
If 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