1.

<script type="text/javascript">
var str="Is this all th05777-89856825ere is50577-456-?";
var model = /\d{4}\-\d{7,8}/g;
document.write(str.match(model));

</script>

输出结果

5777-89856825

备注:

\d{4} 查找4位数字  \d 数字

\d{7,8} 查找7-8位数字

g 是全局匹配 

扩展代码一:

var str="Is this all th05888777-89856825ere is5057788-456-?";
var model = /\d{4}\-\d{7,8}/g; 
var t = str.match(model);
var n = false;
if(t !=''){
    n = true;
}
document.write(str.match(model));
document.write(n);

输出:

8777-89856825true

 

完美电话正则 

2.

 

扩展:

document.write(patt1.test(str));
document.write(str.match(model));

相关文章:

  • 2021-07-25
  • 2021-12-20
  • 2022-01-29
  • 2021-08-20
  • 2021-12-06
  • 2021-11-07
猜你喜欢
  • 2021-09-11
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2022-02-02
相关资源
相似解决方案