日期:2014-05-16  浏览次数:20372 次

大家看看我的正则为什么不好使!
onkeyup= "this.value=this.value.replace(/[^\({1}\d{3}\){1}\d{3}\-{1}\d{4}]/g, ' ') "
我是要按顺序匹配(121)123-1232

------解决方案--------------------
<script language= "javascript ">
var a= '(121)123-1232 '
alert(a.replace(/(\({1}\d{3}\){1}\d{3}\-{1}\d{4})/g, '$1 '))
</script>

我是要按顺序匹配(121)123-1232注意( 全角或半角

[^]的用法不对,
不知道你要干什么
------解决方案--------------------
<html>
<head>
<script type= "text/javascript ">
function testGG(){
var xxx = document.getElementById( "aaa ");
var re = /(^\($)|(^\(\d$)|(^\(\d\d$)|(^\(\d\d\d$)|(^\(\d\d\d\)$)|(^\(\d\d\d\)\d$)|(^\(\d\d\d\)\d\d$)|(^\(\d\d\d\)\d\d\d$)|(^\(\d\d\d\)\d\d\d\-$)|(^\(\d\d\d\)\d\d\d\-\d$)|(^\(\d\d\d\)\d\d\d\-\d\d$)|(^\(\d\d\d\)\d\d\d\-\d\d\d$)|(^\(\d\d\d\)\d\d\d\-\d\d\d\d$)/
if(re.test(xxx.value)){
return;
}else{
xxx.value= " ";
}
}
</script>
</head>
<body>
<input type= "text " id= "aaa " onkeyup= "testGG() "> <br>
<input type= "button " value= "ok " onClick= "testGG() ">

</body>

</html>