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 i.e
ValidationExpression="\w+([-+.']\w+)@\w+([-.]\w+).\w+([-.]\w+)*"
It is working fine but problem comes when I tried giving non-english letters e.g.
è é ü û ă 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_èéüûă]
.
This is a limitation of the ECMAScript standard; f.e. 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
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.
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