Regular expression for first and last name

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

    After going through all of these answers I found a way to build a tiny regex that supports most languages and only allows for word characters. It even supports some special characters like hyphens, spaces and apostrophes. I've tested in python and it supports the characters below:

    ^[\w'\-,.][^0-9_!¡?÷?¿/\\+=@#$%ˆ&*(){}|~<>;:[\]]{2,}$
    

    Characters supported:

    abcdefghijklmnopqrstwxyz
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    áéíóúäëïöüÄ'
    陳大文
    łŁőŐűŰZàáâäãåąčćęèéêëėįìíîïłńòóôöõøùúûüųū
    ÿýżźñçčšžÀÁÂÄÃÅĄĆČĖĘÈÉÊËÌÍÎÏĮŁ
    ŃÒÓÔÖÕØÙÚÛÜŲŪŸÝŻŹÑßÇŒÆČŠŽ.-
    ñÑâê都道府県Федерации
    আবাসযোগ্য জমির걸쳐 있는
    

提交回复
热议问题