vermaraj
vermaraj

Reputation: 644

javascript regex support for UTF8 characters with Number and letters

How to generate regex for supporting utf8 characters with Numbers [0-9], letters [a-z] and [A-Z].

I am using xregexp library to support utf-8 characters.

Till now i used :

  1. XRegExp("^\p{L}\d{0-9}+$") //Not supporting any of them.
  2. XRegExp("[^\p{N}\p{L}]") //Not supporting any of them.
  3. XRegExp("^\p{L}+$") // Supports only UTF-8 characters, [a-z] and [A-Z] and not [0-9]

Thanks.

Upvotes: 0

Views: 1889

Answers (1)

Cerbrus
Cerbrus

Reputation: 72957

Just use \\p{L}+ in combination with [0-9]:

XRegExp("^(\\p{L}|[0-9])+$")

Note that you need to escape your backslash, there: \\.

To include _/-:

XRegExp("^(\\p{L}|[0-9_/-])+$")

Note that the dash (-) has to be the first or last character in those brackets, due to it's special meaning.

Upvotes: 2

Related Questions