Regular expression for validating name in java

03-Mar-2020 11:17

I'm Nataraja Gootooru, programmer by profession and passionate about technologies.All examples given here are as simple as possible to help beginners.Today we will look into java email validation program. Sometimes we have to validate email address and we can use email regex for that. This is what I have: The User Profile is to let a System Admin do what they want. After all, we know that all people must have a first and last name, right?The Len & Mid bits are to stop initials, or people putting in "S J ". And no single person has more than three or four names total?From your description, I don't think that's what you desire.

Visit Stack Exchange Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Sign up to join this community Looking to stop people putting initials in the First / Last name fields, plus any special characters that you would not associate with a name.

There's even a library of Reg Ex patterns on the site available that users have submitted which are available for your use to help you create your own custom patterns if one doesn't already meet your needs. There's no way to both enforce lowercase trailing letters and preserve internal caps (like Mc Glynn), so it's best to simply accept what the user submitted (like "Sarah Mc Gil Bert A".

This will match "James Woods", "Henry Ian Cusack" (first_mid will be "Harry Ian", last will be "Cusack"), "John Mc Glynn", "Raymond J Reynolds", etc.

The reason it's breaking on names like Mc Gowan is because you're second character class doesn't allow for Capitalized characters.

Use the below regex to match names with Capitalization after the first character.

So we will use a case insensitive flag to create the pattern object.