The text field "First name" is only allowed to contain any of these characters:
.. and the user should be notified with which illegal characters she has entered in the field, if any.
The knee-jerk reaction to this kind of logic is regular expressions, but my knee-jerk reaction to regexp is to avoid it. The above character set probably doesn't fit with any of the predefined regexp notations, so it would probably be nasty anyway.
|Some Guava fruits for coloring up this blog post (image source)|
So, let's put Google Guava to some use. It has some nifty utilities for working with sets and other collections.
If you consider the user's input characters as one set, and the above whitelist characters as a second set, you can find the characters that appear in the first set, but not in the second like this (see the whole class here):
That's pretty much it. I've put a whole example project along with tests on Github.
Here are the tests showing off some usage:
I will probably be adding some more Guava examples to that project over time.