浏览代码

Merge pull request #638 from fhferreira/master

Brazilian phone number and postal code
Phuoc Nguyen 11 年之前
父节点
当前提交
6ae95a3251
共有 2 个文件被更改,包括 37 次插入4 次删除
  1. 30 2
      src/js/validator/phone.js
  2. 7 2
      src/js/validator/zipCode.js

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

@@ -7,7 +7,8 @@
             ES: 'Spain',
             ES: 'Spain',
             FR: 'France',
             FR: 'France',
             GB: 'United Kingdom',
             GB: 'United Kingdom',
-            US: 'USA'
+            US: 'USA',
+            BR: 'Brazil'
         }
         }
     });
     });
 
 
@@ -18,7 +19,7 @@
         },
         },
 
 
         // The supported countries
         // The supported countries
-        COUNTRY_CODES: ['ES', 'FR', 'GB', 'US'],
+        COUNTRY_CODES: ['ES', 'FR', 'GB', 'US', 'BR'],
 
 
         /**
         /**
          * 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
@@ -75,6 +76,33 @@
             		value   = $.trim(value);
             		value   = $.trim(value);
             		isValid = (/^\(?(?:(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?\(?(?:0\)?[\s-]?\(?)?|0)(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}|\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4}|\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3})|\d{5}\)?[\s-]?\d{4,5}|8(?:00[\s-]?11[\s-]?11|45[\s-]?46[\s-]?4\d))(?:(?:[\s-]?(?:x|ext\.?\s?|\#)\d+)?)$/).test(value);
             		isValid = (/^\(?(?:(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?\(?(?:0\)?[\s-]?\(?)?|0)(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}|\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4}|\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3})|\d{5}\)?[\s-]?\d{4,5}|8(?:00[\s-]?11[\s-]?11|45[\s-]?46[\s-]?4\d))(?:(?:[\s-]?(?:x|ext\.?\s?|\#)\d+)?)$/).test(value);
                     break;
                     break;
+                
+                case 'BR':
+                    // Test: http://regexr.com/399m1
+                    /*
+                     *  0800-000-0000
+                     *  0800 000 0000
+                     *  0800.000.0000
+                     *  08000000000
+                     *  1692089-4635
+                     *  16920894635
+                     *  16992089-4635
+                     *  16 99202-4635
+                     *  (16)99202-4635
+                     *  (16)92089-4635
+                     *  (16) 92089-4635
+                     *  (15) 4343-4343
+                     *  +55 15 3702-7523
+                     *  (+55) 15 3702-7523
+                     *  (+55)1537027523
+                     *  (+55)(15)3702-7523
+                     *  (+55) 15 3702-7523
+                     *  (+55) 15 99202-7523
+                     *  99202-4635
+                     */
+                    value   = $.trim(value);
+                    isValid = (/^(([\d]{4}[-.\s]{1}[\d]{3}[-.\s]{1}[\d]{4})|((\(?\+?[0-9]{2}\)?\s?)?(\(?\d{2}\)?\s?)?\d{4,5}[-.\s]?\d{4}))$/).test(value);
+                    break;
 
 
                 case 'US':
                 case 'US':
                 /* falls through */
                 /* falls through */

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

@@ -11,7 +11,8 @@
             NL: 'Dutch postal code',
             NL: 'Dutch postal code',
             SE: 'Swiss postal code',
             SE: 'Swiss postal code',
             SG: 'Singapore postal code',
             SG: 'Singapore postal code',
-            US: 'US zip code'
+            US: 'US zip code',
+            BR: 'Brazilian postal code'
         }
         }
     });
     });
 
 
@@ -21,7 +22,7 @@
             country: 'country'
             country: 'country'
         },
         },
 
 
-        COUNTRY_CODES: ['CA', 'DK', 'GB', 'IT', 'NL', 'SE', 'SG', 'US'],
+        COUNTRY_CODES: ['CA', 'DK', 'GB', 'IT', 'NL', 'SE', 'SG', 'US', 'BR'],
 
 
         /**
         /**
          * Return true if and only if the input value is a valid country zip code
          * Return true if and only if the input value is a valid country zip code
@@ -104,6 +105,10 @@
                 case 'SG':
                 case 'SG':
                     isValid = /^([0][1-9]|[1-6][0-9]|[7]([0-3]|[5-9])|[8][0-2])(\d{4})$/i.test(value);
                     isValid = /^([0][1-9]|[1-6][0-9]|[7]([0-3]|[5-9])|[8][0-2])(\d{4})$/i.test(value);
                     break;
                     break;
+                    
+                case 'BR':
+                    isValid = /^(\d{2})([\.]?)(\d{3})([\-]?)(\d{3})$/.test(value);
+                    break;
 
 
                 case 'US':
                 case 'US':
                 /* falls through */
                 /* falls through */