Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 电话号码验证 Javascript
您好我正在使用 javascript 为表单创建验证。我想使用 if 语句检查电话号码字段,以确保它包含一个 4 位数的区号,然后是一个空格,后跟一个 7 位数的号码。
任何帮助,将不胜感激。
谢谢
所以你需要验证类似的东西1234 1234567
1234 1234567
function isValidTel(numberToTest){ var pattern =/^\d{4} \d{7}$/ return pattern.test(numberToTest); }