php正则匹配为什么不成功

WBOY
Release: 2016-06-13 11:48:09
Original
1136 people have browsed it

php正则匹配为什么不成功?求助
if(preg_match("^[a-zA-Z][a-zA-Z0-9_\-]{5,19}$", "abc-mmm") )
    echo "true";
else echo "false";

?>

想验证账号的正则表达式,字母开头,允许数字,字母,下划线,减号,6-20为,这个表达式为啥不成功啊?

Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in test.php on line 3
false

试过"^[a-zA-Z][a-zA-Z0-9_-]{5,19}$",取掉“\”也不对,求大神知道(utf8格式的)
------解决方案--------------------
那个叫定界符。不加定界符的话,PHP就认定为^[a-zA-Z][a-zA-Z0-9_-]{5,19}$是字符串,而不是变量。

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!