1 Simple regular? Replies to Points

Source: Internet
Author: User
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.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.