簡體   English   中英

PHP驗證逗號分隔的10位電話號碼

[英]PHP Validate comma serprated 10 digit Phone numbers

我試圖從服務器端進行處理以檢查字符串格式是否正確,例如

 $string = "9000010000,9100011000,9000020000      // Its correct pattern
 $string = "9000010000,9100011000,9000020000,   // Its WRONG   Reason comma in last place
 $string = ",9000010000,9100011000,9000020000,   // Its WRONG   Reason comma in first place
 $string = ",9000010000,9100011000,,9000020000,   // Its WRONG  Reason ,,
 $string = "9000010000,9100011,9000020000,   // Its WRONG because Middle no. is not 10 digit

我已經使用此代碼通過JavaScript進行了客戶端驗證

    var listIsOk=/^(\d{10},)*\d{10}$/.test(contact_list);
if(listIsOk==true){
alert("success"
}
else {
alert("string is wrong")
}

我想知道如何在php上實現此目標,謝謝

if (preg_match('/^(\d{10},)*\d{10}$/', $string)) {
  echo 'success';
} else {
  echo 'string is wrong';
}

首先查看php函數explode() ,它將使您可以將字符串拆分為電話號碼數組。 從那里開始,您將需要遍歷並仔細查看每一個,以確定是否正確。

暫無
暫無

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

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