views:

42

answers:

3

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.

+2  A: 

\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_èéüûă].

Gumbo
Thank you Gumbo for your fast response. but its very difficult to get the complete list of characters.
Rahul
@Rahul: Modern regular expression libraries often support various predefined character classes like `\w` is predefined. Some even have a support by [describing the characters by their Unicode character properties](http://www.regular-expressions.info/unicode.html).
Gumbo
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.

buru
Thanks for the reponses, it clarifies the situation.
Rahul
+1  A: 

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
Jan Jongboom
Hi Jan, Thanks for the response. That means i cant validate non-english characters using validator. I cant include client side script now in my application. Is there any other way so i can validate by validatos only?
Rahul