https://blog.csdn.net/nongweiyilady/article/details/74007124
Recently, I have been working on the registration and landing page, which involves the verification of 11-digit valid mobile phone numbers. The code is posted here, hoping to help friends who have this development needs.
- function isPoneAvailable($poneInput) {
- var myreg = / ^ [1] [3,4,5,7,8] [0-9] {9} $ /;
- if (!myreg.test($poneInput.val())) {
- return false;
- } else {
- return true;
- }
- }
Here I directly encapsulate it in a method, and when needed, pass in an input jq object. Of course, you can also pass in strings directly, like:
- function isPoneAvailable(str) {
- var myreg = / ^ [1] [3,4,5,7,8] [0-9] {9} $ /;
- if (!myreg.test(str)) {
- return false;
- } else {
- return true;
- }
- }
The point here is this regular expression:
- var myreg = / ^ [1] [3,4,5,7,8] [0-9] {9} $ /;
This expression means:
1--begins with 1;
2--The second digit can be any one of 3, 4, 5, 7, 8;
3--finally ends with 9 integers from 0-9.
Originally, it only accommodates mobile phone numbers starting with 13, 15, 17, 18, but the test mm says that there are numbers starting with 14, so 14 is added; of course, if it develops into numbers starting with 16, or 19, etc. ,exist
- [3,4,5,7,8]
can be added in.
Pro test feasible 20180428
2017-9-8
- // Determine whether it is a mobile phone number
- isPoneAvailable: function (pone) {
- var myreg = / ^ [1] [3,4,5,7,8] [0-9] {9} $ /;
- if (!myreg.test(pone)) {
- return false;
- } else {
- return true;
- }
- },
- // Determine if it is a phone number
- isTelAvailable: function (tel) {
- var myreg = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3 ,}))?$/;
- if (!myreg.test(tel)) {
- return false;
- } else {
- return true;
- }
- },