A simple regular? Replies to points!
The Phone Number field (tel varchar type) Stores 3 numbers and ends with a semicolon, similar to the following:
0510-12323475,0781-26354589,021-25698746 (storage of 3 numbers simultaneously)
0521-25698745,, (may only store 1 phone numbers)
0521-25698745,021-25698475, (it is possible to store only 2 phone numbers)
Now use the regular to determine whether the phone number entered is normal, pay attention to the telephone area code.
regtel=/^ (\d{3,4}-\d{7,8} (-\d{1,4})?)? $/I wrote this, but I can't.
------Solution--------------------
PHP code
$str = ' 0510-12323475,, '; $pattern = '/,?\d{4}-\d+,?/' ; Var_dump (Preg_match ($pattern, $str));
------Solution--------------------
PHP code
$ar = array (' 0510-12323475,0781-26354589,021-25698746 ', ' 0521-25698745,, ', ' 0521-25698745,021-25698475 ', ' 0317-88641, Ttttttt ',); $pattern = '/(?: \ D{3,}-\d+,|,) {3}/'; foreach ($ar as $v) {$v = Trim ($v). Str_repeat (', ', ' 3-substr_count ($v, ', '));//comma-filled echo $v. ' ' . Preg_match ($pattern, $v), Php_eol;}
------Solution--------------------
Discussion
Boss, I just want to $pattern.
But your $pattern is not good.