Browse Source

Merge pull request #739 from caijh/master

phone validator add support for china phone.
Phuoc Nguyen 11 years ago
parent
commit
044bede5eb
1 changed files with 7 additions and 2 deletions
  1. 7 2
      src/js/validator/phone.js

+ 7 - 2
src/js/validator/phone.js

@@ -21,7 +21,7 @@
         },
         },
 
 
         // The supported countries
         // The supported countries
-        COUNTRY_CODES: ['BR', 'ES', 'FR', 'GB', 'MA', 'PK', 'US'],
+        COUNTRY_CODES: ['BR', 'ES', 'FR', 'GB', 'MA', 'PK', 'US', 'CN'],
 
 
         /**
         /**
          * Return true if the input value contains a valid phone number for the country
          * Return true if the input value contains a valid phone number for the country
@@ -97,7 +97,12 @@
                     value   = $.trim(value);
                     value   = $.trim(value);
                     isValid = (/^0?3[0-9]{2}[0-9]{7}$/).test(value);
                     isValid = (/^0?3[0-9]{2}[0-9]{7}$/).test(value);
                     break;
                     break;
-                
+
+                case 'CN':
+                    //http://regexr.com/39dq4
+                    value   = $.trim(value);
+                    isValid = (/^((00|\+)?(86(?:-| )))?((\d{11})|(\d{3}[- ]{1}\d{4}[- ]{1}\d{4})|((\d{2,4}[- ]){1}(\d{7,8}|(\d{3,4}[- ]{1}\d{4}))([- ]{1}\d{1,4})?))$/).test(value);
+                    break;
                 case 'US':
                 case 'US':
                 /* falls through */
                 /* falls through */
                 default:
                 default: