`preg_match` the Whole String in PHP

前端 未结 3 531
北海茫月
北海茫月 2021-01-26 04:43

This thing really confuses me, pardon my ignorance.

I have a var $name in here that I want to be free from number, I don\'t want any digit to be included in

3条回答
  •  醉话见心
    2021-01-26 05:04

    #3 matches because you have both letters and numbers. Your regex in English basically says

    it matches if there is a non-digit character

    If you want to match only non-digit characters, you have to have the regex match against the entire string and allow for an arbitrary number of characters:

    ^[^\d]+$
    

提交回复
热议问题