Ask question

Ask Questions and Get Answers from Our Community

Answer

Answer Questions and Become an Expert on Your Topic

Contact Staff

Our Experts are Ready to Answer your Questions

javascript filter

root

Well-Known Member
Joined
Dec 31, 2012
Messages
1,153
Reaction score
71
Points
48
Code:
function filterdata(){    var slist = window.document.f.socks.value;
    var kero = slist.match(/\d{1,3}([.])\d{1,3}([.])\d{1,3}([.])\d{1,3}((:)|(\s)+)\d{1,8}/g );
    if(kero){
        var list="";
        for(var i=0;i<kero.length;i++){
            if(kero[i].match(/\d{1,3}([.])\d{1,3}([.])\d{1,3}([.])\d{1,3}(\s)+\d{1,8}/g )){
                kero[i]=kero[i].replace(/(\s)+/,':');
            }
            list=list+kero[i]+"\n";
        }
        window.document.f.socks.value=list;
    }
    else{
        window.document.f.socks.value="";
    }
}
</script>


demo :


2 74.143.213.110:32800 insightbb.com 40502 LEXINGTON KENTUCKY US 0.506703 08:05:46
3 69.66.27.105:47288 iowatelecom.net 91790 WEST COVINA CALIFORNIA US 0.476672 07:35:15
4 74.199.53.208:16816 wideopenwest.com 43085 COLUMBUS OHIO US 0.550737 08:05:36
5 50.163.215.47:31510 comcast.net 15122 PITTSBURGH PENNSYLVANIA US 0.547207 08:35:12


kết quả :

74.143.213.110:32800
69.66.27.105:47288
74.199.53.208:16816
50.163.215.47:31510
 
Code:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fillter</title>
<script>

function filterdata(){  
 var  knoidung=document.getElementById('noidung').value;
    var kero = knoidung.match(/\d{1,3}([.])\d{1,3}([.])\d{1,3}([.])\d{1,3}((:)|(\s)+)\d{1,8}/g );
    if(kero){
        var list="";
        for(var i=0;i<kero.length;i++){
            if(kero[i].match(/\d{1,3}([.])\d{1,3}([.])\d{1,3}([.])\d{1,3}(\s)+\d{1,8}/g )){
                kero[i]=kero[i].replace(/(\s)+/,':');
            }
            list=list+kero[i]+"\n";
        }
    }else
		list="";
	document.getElementById('hienthi').innerHTML=list;
}
</script>
</head>

<body>
<textarea  id="noidung" cols="125" rows="8" wrap="soft">
</textarea>
<button onClick="filterdata()">Filterdata</button>
<a>Ket qua:</a>
<textarea id="hienthi" cols="23" rows="8"></textarea>

</body>
</html>
 
Last edited:
Top