I get a list of names and need to validate them. Some examples:
- Elizabeth T. Bang
- Elizabeth Bang
- Zaki M. F. El-Adawy
- joseph m. pastore, jr.
- Zaki M. F. El-Adawy
How can I use regular expressions in Java to validate them?
I get a list of names and need to validate them. Some examples:
How can I use regular expressions in Java to validate them?
I'd start by listing the rules that dictate a valid name. Just in plain old english. I suspect you'll wind up with a very complicated set of rules and exceptions. Once you've figured that bit out you'll be ready to tackle writing a regex to match them.
You might find the QuickREx Eclipse plugin to be helpful if you are using Eclipse. I use it any time I'm testing and developing complex regular expressions. It lets you specify test input, view all matching groups, etc.
Why do you need to validate names? To catch typos or people just mashing the keyboard? Is it really worth the risk to reject a legitimate customer with an unusual name? There are people with no middle name or more than one, people who only have one name altogether, people who insist on having their title used everywhere, and of course all kinds of non-ASCII characters.