Matching Unicode letter characters in PCRE/PHP

后端 未结 5 990
别跟我提以往
别跟我提以往 2020-11-22 01:13

I\'m trying to write a reasonably permissive validator for names in PHP, and my first attempt consists of the following pattern:

// unicode letters, apostrop         


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 01:37

    I think the problem is much simpler than that: You forgot to specify the u modifier. The Unicode character properties are only available in UTF-8 mode.

    Your regex should be:

    // unicode letters, apostrophe, hyphen, space
    $namePattern = '/^[-\' \p{L}]+$/u';
    

提交回复
热议问题