Adam
Adam

Reputation: 5455

Fast and neat check that a string only contains alphabet, regardless of character set?

Sorry, posted that too soon.

This is the real question:

I require a validation string, that validates a name only contains characters from real alphabets - can be any, unrestricted to one particular.

e.g. it may be Japanese, or Russian, or plain ASCII.

I've looked at Java function to return if string contains illegal characters which is pretty good, but only suitable for Latin languages.

I looked at Validate a string contains only certain characters in java which talks about java.util.Scanner but that wasn't designed for this purpose really.

Upvotes: 0

Views: 481

Answers (1)

Jeremy Grand
Jeremy Grand

Reputation: 2370

As seen in https://stackoverflow.com/a/14662136/7573818, does the following solve your case ?

str.matches("^(?U)[\\p{Alpha}\\-']+")

Upvotes: 2

Related Questions