Name Search – Regex

In this example of regex, we will want to check to see if the user input the correct naming format. This regex is good for a real name validation and it is not a username checker. It is obvious that in a majority of the cases a real name will only have alphabetical characters.

there are two versions of this regex, one will check for length and the other version doesn’t. This first version below will check the following. The entire string must be less than or equal to fifty letters this including the middle space between words. There must not be any space in front or in the back of the string. The string can only contain lower or upper case letters.

/^(?=^.{0,50}$)([a-zA-Z]+(?:(?:\. |[' ])[a-zA-Z]+){0,50})$/g		

This regex below will do exactly the same thing as the above regex. However, it will not check for how long the entire string can be.

/^([a-zA-Z]+(?:(?:\. |[' ])[a-zA-Z]+)*)$/g

This post was written by Kevin and was first post @
Original Post Name: "Name Search – Regex".
Original Post Link:


Random Article You May Like

Leave a Reply

Your email address will not be published. Required fields are marked *