整数只有if-else在php中的条件

时间:2014-02-17 11:27:55

标签: php if-statement integer

我不能只为联系号码

做整数
    if($Contactno=="")
{
    $error['Contactno']="Contactno Is Required.";
}
else
{ 
    if( !preg_match("/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i", $Contactno)) 
        $valid_Contactno=$Contactno;
    }
    else
    {
                    $error['Contactno']="Numbers only.";
    }

1 个答案:

答案 0 :(得分:2)

使用ctype_digit代替检查数字。

if(ctype_digit($Contactno))
 {
   echo "This is a valid contact number !";
 }
else
 {
   echo "You cannot enter characters other than number";
 }