首页 > 其他分享 >js正则过滤字母

js正则过滤字母

时间:2022-08-19 11:49:40浏览次数:80  
标签:replace 正则 过滤 result alert var js reg

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

 

标签:replace,正则,过滤,result,alert,var,js,reg
From: https://www.cnblogs.com/wangshengli520/p/16601459.html

相关文章