浏览代码

add +1 Country Code, (area code)

test: http://regexr.com/38mqi
tomByrer 11 年之前
父节点
当前提交
c381976b16
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      src/js/validator/phone.js

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

@@ -27,8 +27,11 @@
                 case 'US':
                 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\-?)?(\d{3})[\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value) && (value.length == 10);
+                    return (/^(?:(1\-?)|(\+1 ?))?\(?(\d{3})[\)\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value) && (value.length == 10);
             }
         }
     }