views:

191

answers:

1

Hi, how can i write a regular expression to validate name field in a multilingual web application, i want to validate the name field for non-English languages e.g. Spanish or German, and we need to make sure that no one enter digits or special characters. I'm using .NET 2.0

I believe we can't use expression as below for non-English language.

^[a-zA-Z]{1,20}$

Any help will be highly appreciated!

I got this Regular Expression, it works fien when i uses Regex Builder but when i try it in actual web application it fails:

^\p{L}[\p{L}\p{Pd}\x27]*\p{L}$

+3  A: 

use \w for letter. it is multilingual friendly

Andrey
Will it only allow only alphabets with spaces, and no digits and special chracters???
BT
According to http://msdn.microsoft.com/en-us/library/1400241x(VS.85).aspx the \w is equivalent to [A-Za-z0-9_], for J(ava)Script - which is used client-side by a regexvalidator.
Hans Kesting
see the header "JScriptRegular Expression Syntax (Scripting)". it is not .net, it is jscript
Andrey
http://msdn.microsoft.com/en-us/library/20bw873z.aspx#WordCharacter
Andrey
@Andery, so it means it include digit as well, beucase it has Nd this as well: {Nd - Number, Decimal Digit}
BT
yes, it includes them. If you want ONLY letters then specify explicitly using http://msdn.microsoft.com/en-us/library/20bw873z.aspx#CategoryOrBlock
Andrey
^\p{L}[\p{L}\p{Pd}\x27]*\p{L}$ i got this regular expression, it works fine when i test it using RegEx Builder, but it fails when i actually put it in ASP.NET page.
BT
it might be because of culture of thread.
Andrey
@Andrey: infact i'm changing the UI culture and current culture to the language user selects, is it the reason? what should i do??
BT