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));