Regular expression for first and last name

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

    This regex work for me (was using in Angular 8) :

    ([a-zA-Z',.-]+( [a-zA-Z',.-]+)*){2,30}
    

    It will be invalid if there is:-

    1. Any whitespace start or end of the name
    2. Got symbols e.g. @
    3. Less than 2 or more than 30

    Example invalid First Name (whitespace)

    Example valid First Name :

提交回复
热议问题