Regex for names with special characters (Unicode)

前端 未结 7 2246
太阳男子
太阳男子 2020-11-28 09:28

Okay, I have read about regex all day now, and still don\'t understand it properly. What i\'m trying to do is validate a name, but the functions i can find for this on the i

7条回答
  •  渐次进展
    2020-11-28 10:06

    Regarding JavaScript it is more tricky, since JavaScript Regex syntax doesn't support unicode character properties. A pragmatic solution would be to match letters like this:

    [a-zA-Z\xC0-\uFFFF]
    

    This allows letters in all languages and excludes numbers and all the special (non-letter) characters commonly found on keyboards. It is imperfect because it also allows unicode special symbols which are not letters, e.g. emoticons, snowman and so on. However, since these symbols are typically not available on keyboards I don't think they will be entered by accident. So depending on your requirements it may be an acceptable solution.

提交回复
热议问题