Tutorial 1 simple regular expression? Reply to score

Source: Internet
Author: User
What is a simple regular expression? Reply to score! The telephone number field (telvarchar type) stores three numbers and ends with a semicolon, for example, 0510-12323475,0781-26354589,021-25698746 (three numbers are stored simultaneously) 0521-25698745 ,, (It is possible to store only one phone number.) 0521 is a simple regular expression? Reply to score!
The telephone number field (tel varchar type) stores three numbers and ends with a semicolon, similar:
0510-12323475,0781-26354589,021-25698746 (three numbers are stored simultaneously)
0521-25698745, (it is possible to store only one phone number)
0521-25698745,021-25698475, (it is possible to store only two phone numbers)
Now, use regular expressions to determine whether the phone number is normal. pay attention to the telephone area number.
RegTel =/^ (\ d {3, 4}-\ d {7, 8} (-\ d {1, 4 })?)? $/I wrote this, but it does not work.

------ Solution --------------------
PHP code
$ Str = '1970-0510, '; $ pattern = '/,? \ D {4}-\ d + ,? /'; Var_dump (preg_match ($ pattern, $ str ));
------ Solution --------------------
PHP code
$ Ar = array ('2017-12323475,0781-0510-26354589,021 ', '2017-25698746,', '2017-0521-25698745 ', '2017-0521, ttttttt',); $ pattern = '/(? : \ D {3,}-\ d +, |,) {3}/'; foreach ($ ar as $ v) {$ v = trim ($ v ). str_repeat (',', 3-substr_count ($ v, ','); // complete the comma echo $ v. ''. preg_match ($ pattern, $ v), PHP_EOL ;}
------ Solution --------------------
Discussion
Boss, I only need the regular expression of $ pattern. But your $ pattern won't work.

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.