I have a display name field which i have to validate using JavaScript regex. We have to match all language characters like chinese, german, spanish in addition to english language characters except special characters like *(). I am struck on how to match those non-latin characters. Any help appreciated.
views:
105answers:
3
+3
Q:
how to match all language characters like english, greek, chinese except the special characters
A:
Unluckily there isnt much support for unicode for unicode regular expressions in javascript
Parhs
2010-04-29 09:46:04
so i would use ajax (in case javascript is enabled)..or simple server side validation
Parhs
2010-04-29 09:49:02
A:
I've used bits of XRegExp for this kind of thing and it's worked as expected so far. There's Unicode plug-ins here: http://xregexp.com/plugins/
Tim Down
2010-04-29 09:49:25
+1
A:
If your regular expression engine can match Unicode categories, the regex \p{L}
matches any letter in any language. JavaScript does not support Unicode categories. If you use XRegExp with the Unicode plugin, then you can do it like this in JavaScript:
XRegExp('^\\p{L}+$').test($input)
This will return true if $input consists of one or more letters and nothing else.
Jan Goyvaerts
2010-05-02 03:20:09