Home  >  Article  >  Backend Development  >  突然懵了,php正则如何匹配是否满足指定格式?

突然懵了,php正则如何匹配是否满足指定格式?

WBOY
WBOYOriginal
2016-06-23 14:20:32901browse


很简单的要求我居然不清楚了,不知道要用哪个函数了。

我要求用户输入的信息只能是字母,不能有其他任何字符:我使用的是preg_match,仔细一想,preg_match仅仅是匹配用户输入是否含有字母,而不是只有字母,
如,用户输入123abcd456,我要是使用preg_match会得到用户输入是正确的结论,但是这明显是不对的,我要的是用户输入只能是字母,而不是含有,应该用哪个函数啊?

谢谢


回复讨论(解决方案)

/^[a-z]+$/i 只匹配字母

/^[a-z]+$/i 只匹配字母

版主v5!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn