javascript filter

Discussion in 'Java Script' started by root, Jan 2, 2014.

  1. root

    root Active Member

    Joined:
    Dec 31, 2012
    Messages:
    1,177
    Likes Received:
    18
    Trophy Points:
    38
    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
     
  2. StarWar

    StarWar New Member

    Joined:
    Dec 8, 2013
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    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: Jan 8, 2014
  3. nontakjaba

    nontakjaba Member

    Joined:
    Dec 10, 2017
    Messages:
    103
    Likes Received:
    0
    Trophy Points:
    16
    Gender:
    Male
    Cam on ban da chia se
     

Share This Page