C# Regex - Accept spaces in a string

后端 未结 3 936
予麋鹿
予麋鹿 2020-12-20 20:53

I have an application which needs some verifications for some fields. One of them is for a last name which can be composed of 2 words. In my regex, I have to accept these sp

3条回答
  •  不知归路
    2020-12-20 20:54

    You need to escape the last - character - ñ-\s is parsed like the range a-z:

    @"^[a-zA-Zàéèêçñ\s][a-zA-Zàéèêçñ\-\s]+$"
    

    See also on Regex Storm: [a-\s] , [a\-\s]

提交回复
热议问题