I have added a regular expression from a site to verify user name and and it should work but it is giving some error on the compile time. Please see the image and then I googled and learned that few of chars like ‘\w’ is not going to work because js does not support it. Now I don’t know how to convert it , can anyone please help to convert this to workable with ASP.NET MVC data-annotations.
[RegularExpression("^([a-zA-Z])[a-zA-Z_-]*[\w_-]*[\S]$|^([a-zA-Z])[0-9_-]*[\S]$|^[a-zA-Z]*[\S]$")]
Thank you all in advance.
Make your string a literal by adding @ sign before the opening quote. Otherwise you would need to escape all the backslashes that the string contains. That would make regular expression like this even less readable.