We are Borg We are Borg - 1 year ago 129
Java Question

Java, Regex : Adding umlaut and other german characters for first-name

I want to validate first-name sent by user with Regex. I found multiple expressions for first-name, but I also want to add german characters like

and french ones
à À è È é É ù Ù ì Ì ò Ò ñ Ñ
to it. I tried regex evaluator suggested by SO here, but that didn't help. Wheneever I would make an extra square bracket, it would tell me
Your regular expression does not match the subject string.
. What am I doing wrong?

Current Regex pattern :


Thank you.

Answer Source

It is not a good idea to restrict people's names too much, I suggest a rather generic regex:


This regex will match a string only consisting of 1 or more Unicode letters, diacritics, whitespaces, apostrophes or hyphens.

If you need more restrictive checks, like a whitespace may only appear inside the string and only if not consecutive, use grouping:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download