Just try with:
$input = '604-555-5555';
if (preg_match('/^\d{10,13}$/', str_replace('-', '', $input))) {
// valid
}
문제
I need to deliver (international) phone numbers from a PHP registration form to an external party. The external party has the following rules for phone numbers.
This means the following numbers are correct
What would be the best (and most correct) regex to regulate and check all the phone numbers so I can store them in a global database to send them to the external party afterwards?
해결책
Just try with:
$input = '604-555-5555';
if (preg_match('/^\d{10,13}$/', str_replace('-', '', $input))) {
// valid
}
다른 팁
<?php
$input = '604-555-5555';
if (preg_match('/[\d-]{10,13}+/', $input, $r) ) {
// valid
foreach($r as $e){echo $e;}do formatting
}
?>