<?
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 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>php 判斷數字或身份證Regex</title>
</head>
<body>
<form id="111cnNet" name="111cnNet" method="post" action="">
<input name="url" type="text" />
<input name="" type="submit" value="提交 "/>
</form>
</body>
</html>