I have email field in my page, which i am validating using regular expression validator provided my asp.net. I am using same validation expression as given along with validator for emails ie
ValidationExpression="\\w+([-+.']\\w+) @\\w+([-.]\\w+) .\\w+([-.]\\w+)*"
It is working fine but problem comes when I tried giving non-english letters eg
è é ü û ă etc.
But my problem is, when i use same expression in javascript it allows these characters, even at server side also same expression allows these characters.
I think '\\w' allows all alphanumeric characters as well as non english characters but I dont know why it is not allowing when using it in validator.
Please suggest if I did anythig wrong.
\\w
means word character. And the definition of a word character may differ from implementation to implementation. Some do only use [A-Za-z0-9_]
while others also include non-US-ASCII characters (see “ascii-only” in comparison of regular expression flavors ).
If you want to make sure that the same characters are used, list them explicitly like [A-Za-z0-9_èéüûă]
.
It's a known issue: ASP.Net regular expression client-side validator is buggy for non-English characters. You may either use server-side validation (if it's an option), or write your own client-side CustomValidator.
This is a limitation of the ECMAScript standard; fe in .NET \\w
does also match non-english chars.
The simplest solution is to turn off client-side validation as you are working with ASP.NET, so the server-side validator (which uses the .NET implementation) will validate accordingly.
var r = new Regex(@"\w");
foreach(var m in r.Matches("è é ü û a"))
Console.WriteLine(m);
Output:
è
é
ü
û
a
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.