ソースを参照

Merge branch 'master' of https://github.com/gercheq/bootstrapvalidator into gercheq-master

Conflicts:
	src/js/validator/phone.js
nghuuphuoc 11 年 前
コミット
de084f1d14
2 ファイル変更8 行追加9 行削除
  1. 7 8
      src/js/validator/phone.js
  2. 1 1
      src/js/validator/zipCode.js

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

@@ -22,16 +22,15 @@
                 return true;
             }
 
-            var country = (options.country || 'US').toUpperCase();
-            switch (country) {
+            options.country = options.country || 'US';
+            switch (options.country.toUpperCase()) {
                 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:
-                    // Make sure US phone numbers have 10 digits
-                    // May start with 1, +1, or 1-; should discard
-                    // Area code may be delimited with (), & sections may be delimited with . or -
-                    // Test: http://regexr.com/38mqi
-                    value = value.replace(/\(|\)|\s+/g, '');
-                    return (/^(?:(1\-?)|(\+1 ?))?\(?(\d{3})[\)\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value) && (value.length == 10);
+                    value = value.replace(/\D/g,'');
+                    return (/^(?:1\-?)?(\d{3})[\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value);
             }
         }
     }

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

@@ -34,7 +34,7 @@
                     return /^(S-)?\d{3}\s?\d{2}$/i.test(value);
                 case 'US':
                 default:
-                    return /^\d{5}([\-]\d{4})?$/.test(value);
+                    return /^\d{4,5}([\-]\d{4})?$/.test(value);
             }
         }
     };