2017-03-17 26 views
0

你好,我正在嘗試編寫一個代碼,當我給出一個URL時,我將從網站上導出電話號碼。但是,此代碼顯示網站內的所有號碼,如何修改此代碼以檢索英國電話號碼?。任何幫助,建議或批評表示讚賞。受此啓發http://www.convertcsv.com/phone-extractor.htm
代碼顯示在下面,謝謝。Json Regex字符串電話號碼導出

<script> 
    function assignText(s) { 
     document.getElementById('txt1').value = s; 
    } 
    function runit(s) { 
    eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('5 t,j,k,v;5 B=3.6("V").l;5 z=3.6("W").l;5 a=[];5 m=3.6("T").l;5 E=3.6("R").l;5 h="Y";5 e=4;7(3.6("x")){e=3.6("x").9;7(11(e))e=4;J e*=1}5 r={};r.C=L 10("\\\\+?\\\\(?\\\\d*\\\\)? ?\\\\(?\\\\d+\\\\)?\\\\d*([\\\\s./-]\\\\d{2,})+","g");5 c=3.6("G").9*1||1;7(c<1)c=1;5 8=P(3.N[0].K);7(8=="o")8=3.6("M").9;7(!8)8=",";5 A=r.C;5 a=s.O(A)||[];a=p.I(a,D(f){F f.w()});a=p.H(a,D(f){F f.X().w().q>=e&&!(/\\d\\d\\d\\d-\\d\\d-\\d\\d/.Z(f))});7(z)a=a.12();7(B)a=p.13(a,Q);3.6(\'i\').9="";5 b=[];7(m&&c>1){b.y(h+"1");u(j=2;j<=c;j++){b.y(h+j)}h=b.S(8)}7(m){3.6(\'i\').9+=h+"\\n"}u(j=0;j<a.q;){u(k=0;k<c;k++,j++){7(j<a.q){v=a[j].w();7(E)v=v.U(8);3.6(\'i\').9+=v}7(k<c-1){3.6(\'i\').9+=8}}3.6(\'i\').9+="\\n"}',62,66,'|||document||var|getElementById|if|delimiter|value|||cols||minLen|||heading|txta|||checked|hdr|||_|length|res|||for||trim|txtMinLen|push|sorted|re|dup|phone|function|forceCsv|return|txtNumCols|filter|map|else|outsep|new|outSepOtherVal|forms|match|radiovalue|true|chkForceCsv|join|chkCsvHeader|toCsv|chkDup|chkSort|removePunctuation|Phone|test|RegExp|isNaN|sort|uniq'.split('|'),0,{})) 

    } 


    </script> 

回答

0

你可以嘗試使用谷歌的libphonenumber,它有一個JavaScript實現:

https://github.com/googlei18n/libphonenumber

圖書館有一個名爲解析

parse(text, options) 

文本參數功能將是你的電話號碼,在選項參數中,您可以輸入country code。當圖書館能夠將該號碼解析爲英國電話號碼時,您知道號碼是有效的。