浏览代码

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

Conflicts:
	src/js/validator/phone.js
nghuuphuoc 11 年之前
父节点
当前提交
a90e013df3
共有 1 个文件被更改,包括 8 次插入7 次删除
  1. 8 7
      src/js/validator/phone.js

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

@@ -22,15 +22,16 @@
                 return true;
             }
 
-            options.country = options.country || 'US';
-            switch (options.country.toUpperCase()) {
+            var country = (options.country || 'US').toUpperCase();
+            switch (country) {
                 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:
-                    value = value.replace(/\D/g,'');
-                    return (/^(?:1\-?)?(\d{3})[\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value);
+                    // 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(/\D/g, '');
+                    return (/^(?:(1\-?)|(\+1 ?))?\(?(\d{3})[\)\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value) && (value.length == 10);
             }
         }
     }