在发送到数据库之前,在php中为手机号码添加前缀


Add prefix to mobile number in php before sending it to database

可能重复:
请帮助我在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。

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

 //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";