Regular expression for validating name

«» Match either the regular expression below (attempting the next alternative only if this one fails) «[A-Z][a-z][- ]» Match a single character in the range between “A” and “Z” «[A-Z]» Exactly 1 times «» Match a single character in the range between “a” and “z” «[a-z]» Between one and 30 times, as many times as possible, giving back as needed (greedy) «» Match a single character present in the list “- ” «[- ]» Between zero and one times, as many times as possible, giving back as needed (greedy) «» Or match regular expression number 2 below (attempting the next alternative only if this one fails) «[A-Z][- \'][A-Z][a-z][- ]» Match a single character in the range between “A” and “Z” «[A-Z]» Exactly 1 times «» Match a single character present in the list below «[- \']» Exactly 1 times «» One of the characters “- ” «- » A ' character «\'» Match a single character in the range between “A” and “Z” «[A-Z]» Between zero and one times, as many times as possible, giving back as needed (greedy) «» Match a single character in the range between “a” and “z” «[a-z]» Between one and 30 times, as many times as possible, giving back as needed (greedy) «» Match a single character present in the list “- ” «[- ]» Between zero and one times, as many times as possible, giving back as needed (greedy) «» Or match regular expression number 3 below (the entire group fails if this one fails to match) «[a-z][ -\'][A-Z][a-z]» Match a single character in the range between “a” and “z” «[a-z]» Between one and 2 times, as many times as possible, giving back as needed (greedy) «» Match a single character in the range between “ ” and “'” «[ -\']» Exactly 1 times «» Match a single character in the range between “A” and “Z” «[A-Z]» Exactly 1 times «» Match a single character in the range between “a” and “z” «[a-z]» Between one and 30 times, as many times as possible, giving back as needed (greedy) «» I know this validation totally assumes that every person filling out the form has a western name and that may eliminates the vast majority of folks in the world.

regular expression for validating name-43

I have searched and searched and played and played with it and although it is not perfect it may help others making the attempt to validate first and last names that have been provided as one variable. I used the following code for my PHP: if (preg_match('/\b([A-Z][a-z][- ]|[A-Z][- \'][A-Z] [a-z][- ]|[a-z][ -\'][A-Z][a-z])/', $name) # there is no space line break between in the above "if statement", any that # you notice or perceive are only there for formatting purposes.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?NET applications through the Regular Expression Validator control and the Regex class in the System. You can use regular expressions to restrict the range of valid characters, to strip unwanted characters, and to perform length and format checks.You can constrain the input format by defining patterns that the input must match.

Leave a Reply