Home >Backend Development >PHP Tutorial >正则表达式验证老是失败

正则表达式验证老是失败

WBOY
WBOYOriginal
2016-06-23 14:12:40807browse

<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>


回复讨论(解决方案)

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

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

现在还能用ereg么?

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

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

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

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