簡體   English   中英

如何使用php驗證所有國家/地區的電話號碼

[英]How do i validate all countries phone number with php

有沒有辦法用php驗證所有國家的電話號碼

您可以通過使用preg_match來實現,我認為不存在任何自動驗證

通過使用數據庫存儲格式,然后使用輸入的電話號碼檢查格式

int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )

例如。,

<?php
// The "i" after the pattern delimiter indicates a case-insensitive search
if (preg_match("/php/i", "PHP is the web scripting language of choice.")) {
    echo "A match was found.";
} else {
    echo "A match was not found.";
}
?>

看到這個http://php.net/manual/en/function.preg-match.php

從以下位置獲取有關國家/地區電話號碼起始碼的信息:
http://www.international-dialing-codes.net/
插入數據庫,創建數組,在while循環中從DB獲取信息,然后創建foreach ..諸如此類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM