-5

可能重复:
请帮我验证 php 形式的手机号码

我有手机号码要验证,但我卡在前缀部分。

if(empty($_POST['mobileno'])) // phone number is not empty
{
$error[] = 'Please enter mobile number';
} else {
if(preg_match('/^\d{10}$/',$_POST['mobileno'])) // phone number is valid
{
  $mobile = $_POST['mobileno'];
  // your other code here
}
else // phone number is not valid
{
  $error[] = 'Phone number invalid !';
}
}
$prefix = 0;
$pmobile = $prefix . $mobile;

这就是我要为前缀做的事情。这是正确的,因为我不能在数字前添加值 0。

4

1 回答 1

0

您是否尝试过使用正则表达式?

 //check the first section is singular or multi, check area code between 0 and 9, check any additional integers
 $pattern = "[0|00]+[0-9]+[^\\s]";
 $phone_number = "000263712702879"; //international phone number
 if(preg_match($pattern, $phone_number)) {
      echo "this is a number";
 } else echo "this not a number";
于 2012-08-02T23:01:37.047 回答