正则表达式验证老是失败

WBOY
Release: 2016-06-23 14:12:40
Original
770 people have browsed it

<body>        <?php        if(!empty($_POST[sub]))        {                    if(ereg("\d{10}", $_POST[username]))                {echo "验证通过。";}        else        {echo "验证失败";}        }        ?>        <form action="" method="post">    用户名<input type="text" name="username"><br>    <input type="submit" name="sub" value="提交"></form>    </body>
Copy after login


回复讨论(解决方案)

我要验证一个位数为10位的数字、

if(preg_match("/^\d{10}$/", $_POST[username]))

现在还能用ereg么?

ereg(" [0-9]{10}", $_POST[username])

现在还能用ereg么?
求问大神?为什么不使用了?

Deprecated:  Function ereg() is deprecated 
Deprecated 已过时

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!