Regular expression for first and last name

后端 未结 24 1947
温柔的废话
温柔的废话 2020-11-22 10:03

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

For the first name, it should only contain letters, can be several words with spaces, an

24条回答
  •  花落未央
    2020-11-22 10:21

    For first and last names theres are really only 2 things you should be looking for:

    1. Length
    2. Content

    Here is my regular expression:

    var regex = /^[A-Za-z-,]{3,20}?=.*\d)/

    1. Length

    Here the {3,20} constrains the length of the string to be between 3 and 20 characters.

    2. Content

    The information between the square brackets [A-Za-z] allows uppercase and lowercase characters. All subsequent symbols (-,.) are also allowed.

提交回复
热议问题