Browse Source

makes sure US phone numbers have 10 digits

Gercek Karakus 11 years ago
parent
commit
f6616bcbf5
1 changed files with 3 additions and 0 deletions
  1. 3 0
      src/js/validator/phone.js

+ 3 - 0
src/js/validator/phone.js

@@ -25,6 +25,9 @@
             options.country = options.country || 'US';
             options.country = options.country || 'US';
             switch (options.country.toUpperCase()) {
             switch (options.country.toUpperCase()) {
                 case 'US':
                 case 'US':
+                  // Make sure US phone numbers have 10 digits
+                  value = value.replace(/\(|\)|\s+/g, '');
+                  return (/^(?:1\-?)?(\d{3})[\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value) && value.length == 10;
                 default:
                 default:
                     value = value.replace(/\(|\)|\s+/g, '');
                     value = value.replace(/\(|\)|\s+/g, '');
                     return (/^(?:1\-?)?(\d{3})[\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value);
                     return (/^(?:1\-?)?(\d{3})[\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value);