Question

I need input validation, good input validation to keep everything clean. So I want a strict regular expression on "full name", international so I need Unicode support. I downloaded XRegExp, which compiles "their format" to regular expressions and supports Unicode however:

Correct names:

  • John Elkjærd
  • André Svenson
  • Marco d'Almeida
  • Kristoffer la Cour

Incorrect names:

  • Hans
  • H4nn3 Andersen
  • Martin Henriksen!

So I need:

  1. Match unicode letter (a, æ)
  2. Match unicode accents (á, Ë etc.)
  3. Match unicode hyphens (- _ etc)

In PHP I can do the following operations to match:

\p{L} (unicode letter)
\p{Mn} (unicode accents)
\p{Pd} (unicode hyphens)

What I figured out, that I can do with XRegExp:

^\p{L}+$ would match '日本' so only the letter one works, but how can I figure out how to do these unicode accents, hypens?

Thanks for help.

Was it helpful?

Solution

It looks like @lanzz gave you some good feedback about potential issues with name validation, but for the record, you can use the Unicode categories you mentioned with XRegExp just as you would with PHP. E.g., XRegExp('^[\\p{L}\\p{Mn}\\p{Pd} ]+$'). This requires XRegExp's Unicode Categories addon. Note that the backslashes are escaped due to JavaScript string literal escaping rules.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top