Advice on how to validate names and surnames using regex

前端 未结 3 1391
我在风中等你
我在风中等你 2021-01-07 05:22

I want to validate name and surname for my Ruby on Rails 3 application and so I have posted this question. Someone adviced me to read the Falsehoods Progra

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-07 05:55

    The correct way to validate names is:

    1. Accept any and all possible Unicode characters.
    2. Reject inputs of length 0.
    3. Make sure the result has at least one character that is neither of type \pM, \pZ, nor \pC; i.e., is neither one of the combining marks, separators, nor other (usually control) characters. A character class like [^\pM\pC\pZ] should suffice.

    There: easy as can be. You will probably need Ruby 1.9 to do this properly, though.

提交回复
热议问题