skip to content »

Regular expression for validating name

regular expression for validating name-67

# # pass - successful match - do something } else { # fail - unsuccessful match - do something I am learning Reg Ex myself but I do have the explanation for the code as provided by Reg Ex buddy.Here it is: Assert position at a word boundary «\b» Match the regular expression below and capture its match into backreference number 1 «([A-Z][a-z][- ]|[A-Z][- \'][A-Z][a-z][- ]|[a-z][ -\'][A-Z][a-z])» Between 2 and 5 times, as many times as possible, giving back as needed (greedy) «» Note: I repeated the capturing group itself. Put a capturing group around the repeated group to capture all iterations.

regular expression for validating name-16regular expression for validating name-25regular expression for validating name-4regular expression for validating name-30

Anyway, a-z A-Z precludes characters that are alphabetical from any Unicode region beyond the lower 128. And let's not forget names from languages that have clicks in them, like the ! So in other words, name validation is impossible, as Steven Soroka's referenced article points out.And there are no names that use special characters, symbols, or apostrophes?I think your choice of Reg Ex to validate names is missing the point: this is a huge unwieldy problem and, even if you massively restrict the scope of names you allow, you will forever suffer the risk of false negatives and you will be turning away people from other cultures and languages.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?There is probably a more elegant way of doing this but I'm rather fresh to REGEX. And no doubt the same person will forever be identifiable by the same name?I understand why although I'm stumped to provide a solution.

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?

Username is valid : mkyong34 , true Username is valid : mkyong_2002 , true Username is valid : mkyong-2002 , true Username is valid : mk3-4_yong , true username is valid : mk , false username is valid : [email protected] , false username is valid : mkyong123456789_- , false PASSED: Valid Username Test([ String;@116471f) =============================================== com.mkyong.regex.

For website validation purposes, I need first name and last name validation.

Plus, we know that no modern culture uses patronymic naming and people in the same nuclear family must have the same last name, right?

Well, we can at least assume that people do not have single character names, right?

To validate other forms of input, such as query strings, cookies, and HTML control input, you can use the System. The attacker can then supply carefully crafted input that compromises your application by attempting SQL injection, cross-site scripting, and other injection attacks.