How to validate that a string only contain lowercase letters?

后端 未结 3 830
日久生厌
日久生厌 2020-12-04 01:40

I\'m trying to verify that my string matches a pattern. That is, the full string can be written as that pattern. However preg_match returns true, i

3条回答
  •  执念已碎
    2020-12-04 02:19

    You use the start and end markers, ^ and $ respectively, to indicate beginning and end of the string in your regular expression pattern. That way you can make the expression match only the whole string, not any kind of substring. In your case it would then look like this:

    preg_match("#^[a-z]*$#", "333k");
    

    You can also, with one these markers, specify that the pattern must only match the beginning or the end of the string.

提交回复
热议问题