js正则过滤字母

<input type="text" id="txt" />

<input type="button" onclick="check()" value="检测输入"/>

<script>

function check(){

    var reg=/[A-Za-z]/g;

    var input=document.getElementById("txt").value;

    var result=input.replace(reg,"");

    alert(result);

}

</script> 

  

<script language="JavaScript" type="text/javascript">
var a='asdfas123^dfa123'
alert(a.replace(/[a-z]/gi,""))
</script>

 

posted @ 2022-08-19 11:32  南瓜壳  阅读(308)  评论(0编辑  收藏  举报