php 判断数字或身份证正则表达式
<?php function funcNum($str, $num1 = '', $num2 = '') //数字正则表达试 { if ($num1 != '' and $num2 != '') { return (preg_match("/^[0-9] {" . $num1 . "," . $num2 . "}$/", $str)) ? true : false; } else { return (preg_match("/^[0-9]/", $str)) ? true : false; } } function funcCard($str) // { return (preg_match('/(^([\d]{15}|[\d]{18}|[\d]{17}x)$)/', $str)) ? true : false; } if ($_POST) { if (funcNum($_POST['url'])) { echo '是数字'; } else if (funcCard($_POST['url'])) { exit('是身份证号码'); } else { echo '不是数字了不是身份证号'; } } ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>php 判断数字或身份证正则表达式</title> </head> <body> <form id="phprm" name="phprm" method="post" action=""> <input name="url" type="text" /> <input name="" type="submit" value="提交 "/> </form> </body> </html>
本文链接:http://www.phprm.com/code/84c42c2226120d428a7d1a3ce6c9c601.html
收藏随意^^请保留教程地址.