Browse Source

Added German ZIP code and phone number validators

jhadenfeldt 11 years ago
parent
commit
cf4be0ef2a
2 changed files with 14 additions and 2 deletions
  1. 8 1
      src/js/validator/phone.js
  2. 6 1
      src/js/validator/zipCode.js

+ 8 - 1
src/js/validator/phone.js

@@ -7,6 +7,7 @@
             BR: 'Brazil',
             CN: 'China',
             CZ: 'Czech Republic',
+            DE: 'Germany',
             DK: 'Denmark',
             ES: 'Spain',
             FR: 'France',
@@ -29,7 +30,7 @@
         },
 
         // The supported countries
-        COUNTRY_CODES: ['BR', 'CN', 'CZ', 'DK', 'ES', 'FR', 'GB', 'MA', 'PK', 'RO', 'RU', 'SK', 'TH', 'US', 'VE'],
+        COUNTRY_CODES: ['BR', 'CN', 'CZ', 'DE', 'DK', 'ES', 'FR', 'GB', 'MA', 'PK', 'RO', 'RU', 'SK', 'TH', 'US', 'VE'],
 
         /**
          * Return true if the input value contains a valid phone number for the country
@@ -85,6 +86,12 @@
                     isValid = /^(((00)([- ]?)|\+)(420)([- ]?))?((\d{3})([- ]?)){2}(\d{3})$/.test(value);
                     break;
 
+                case 'DE':
+                    // Test: http://regexr.com/39pkg
+                    value   = $.trim(value);
+                    isValid = (/^(((((((00|\+)49[ \-/]?)|0)[1-9][0-9]{1,4})[ \-/]?)|((((00|\+)49\()|\(0)[1-9][0-9]{1,4}\)[ \-/]?))[0-9]{1,7}([ \-/]?[0-9]{1,5})?)$/).test(value);
+                    break;
+
                 case 'DK':
                     // Mathing DK phone numbers with country code in 1 of 3 formats and an
                     // 8 digit phone number not starting with a 0 or 1. Can have 1 space

+ 6 - 1
src/js/validator/zipCode.js

@@ -7,6 +7,7 @@
             BR: 'Brazil',
             CA: 'Canada',
             CZ: 'Czech Republic',
+            DE: 'Germany',
             DK: 'Denmark',
             FR: 'France',
             GB: 'United Kingdom',
@@ -29,7 +30,7 @@
             country: 'country'
         },
 
-        COUNTRY_CODES: ['BR', 'CA', 'CZ', 'DK', 'FR', 'GB', 'IE', 'IT', 'MA', 'NL', 'RO', 'RU', 'SE', 'SG', 'SK', 'US'],
+        COUNTRY_CODES: ['BR', 'CA', 'CZ', 'DE', 'DK', 'FR', 'GB', 'IE', 'IT', 'MA', 'NL', 'RO', 'RU', 'SE', 'SG', 'SK', 'US'],
 
         /**
          * Return true if and only if the input value is a valid country zip code
@@ -86,6 +87,10 @@
                     isValid = /^(\d{3})([ ]?)(\d{2})$/.test(value);
                     break;
 
+                case 'DE':
+                    isValid = /^([01245678][0-9]{4})$/.test(value);
+                    break;
+
                 case 'DK':
                     isValid = /^(DK(-|\s)?)?\d{4}$/i.test(value);
                     break;