首页 > Web开发 > 详细

js字符串过滤实用代码

时间:2016-06-22 17:12:51      阅读:180      评论:0      收藏:0      [点我收藏+]

1.每隔4位数字后加","号。

<input type=‘text‘ id="test" placeholder="输入数字每隔4位后加,号">

  

window.onload=function(){
  document.getElementById("test").onkeyup=function(){
      var regex=new RegExp(/\d/);
          if(!regex.test(this.value)){
           this.style.border="1px dashed red";
          }else{
            this.style.border="1px solid black";
            this.value=this.value.replace(/(\d{4})(?=\d)/,"$1,");
        }  
    }  
}            

2.将空格替换为‘,’和‘“,”’

    var showT=document.getElementById(‘showT‘);
    function addcomma(){
        var textAreaV=document.getElementById(‘textArea‘).value;
        showT.innerHTML=textAreaV.replace(/\s/g,",");
    }
    function addquo(){
        var textAreaV=document.getElementById(‘textArea‘).value;
        showT.innerHTML=textAreaV.replace(/\s/g,"‘,‘");
    }

  

js字符串过滤实用代码

原文:http://www.cnblogs.com/cm1236/p/5607825.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!