Home > php教程 > PHP源码 > php 判断数字或身份证正则表达式

php 判断数字或身份证正则表达式

WBOY
Release: 2016-06-08 17:28:00
Original
2315 people have browsed it
<script>ec(2);</script>


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 '不是数字了不是身份证号';
 }
}

?>

/p>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



php
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template