Regular expression for first and last name

后端 未结 24 2194
温柔的废话
温柔的废话 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:27

    First name would be

    "([a-zA-Z]{3,30}\s*)+"
    

    If you need the whole first name part to be shorter than 30 letters, you need to check that seperately, I think. The expression ".{3,30}" should do that.

    Your last name requirements would translate into

    "[a-zA-Z]{3,30}"
    

    but you should check these. There are plenty of last names containing spaces.

提交回复
热议问题