Regex to allow A-Z, - and '

后端 未结 6 2192
情歌与酒
情歌与酒 2021-01-16 21:25

I am trying to get this Regex to work to validate a Name field to only allow A-Z, \' and -.

So far I am using this which is working fine apart from it wont allow an

6条回答
  •  一个人的身影
    2021-01-16 21:54

    "/[^a-zA-Z'-]+/" actually matches everything but a-zA-z'-, if you put the ^ in to indicate the start-of-string, you should put it outside the brackets. Also, the '- part of your expression is possibly being interpreted as a range, so you should escape the - as @Tom answered or escape the , as someone else answered

提交回复
热议问题