用户操作
[即时聊天] [发私信] [加为好友]
徐兴ID:striker_un
2491次访问,排名2万外好友7人,关注者11
striker_un的文章
原创 8 篇
翻译 0 篇
转载 1 篇
评论 2 篇
最近评论
striker_un:常用查询字符串处理
function chk_query($word) {
global $skip_ary,$split_ary,$trans_ary;
$res = urldecode($word);
$res .= ' '.strtoupper($res);
$res = strtr($res,$split_ary);
DOLOY:16 yellow card ,4 red
文章分类
收藏
    相册
    徐兴
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 关于js处理的一些公用代码收集.(代码+demo)收藏

    新一篇: 批量 gb->utf-8编码转换. (转) | 旧一篇: 俺用的数据库类,发布出来。PHP mysql

    关于js字符串的.prototype 的一个扩展.
    // JavaScript Document
     String.prototype.Trim=function(){return   this.replace(/(^s*)|(s*$)/g,"");}   

     String.prototype.cleanStyle
    =function(){
         
        
    var html =this ;
        
    //清除 Hd 标记
        html = html.replace( /<Hd>(.*)</Hd>/gi, '$1' ) ;
        
    //html = html.replace( /<Hd>s*</Hd>/gi, '' ) ;
        
        
        
        
    //去掉其中的一个样式属性。 修如.
        //remove Styles
        html = html.replace(/<(w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3" ) ;
        
    // remove Class
        html = html.replace(/<(w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
        
        html 
    = html.replace(/<!--.*-->/ig, "" ) ;
        
        
    //去除多余的span 标签.
        html = html.replace( /<SPANs*[^>]*>s*&nbsp;s*</SPAN>/gi, '&nbsp;' ) ;
        html 
    = html.replace( /<SPANs*[^>]*></SPAN>/gi, '' ) ;
        
        html 
    = html.replace( /<(U|I|STRIKE|B|STRONG)>(.*)</1>/ig, '$2' ) ;
        
        
    // Remove empty tags (three times, just to be sure).
        // This also removes any empty anchor
        html = html.replace( /<([^s>]+)(s[^>]*)?>s*</1>/g, '' ) ;
        html 
    = html.replace( /<([^s>]+)(s[^>]*)?>s*</1>/g, '' ) ;
        html 
    = html.replace( /<([^s>]+)(s[^>]*)?>s*</1>/g, '' ) ;
        
        
    return html;
    }
       

    //html编码.
    String.prototype.htmlEncode =function()
    {
        text 
    = this;
        
        text 
    = text.replace(/&/g, "&amp;") ;
        text 
    = text.replace(/"/g, "&quot;") ;
        text = text.replace(/</g, 
    "&lt;") ;
        text = text.replace(/>/g, 
    "&gt;") ;
        text = text.replace(/'/g, 
    "&#39;") ;

        return text ;
    }


    //html解码.
     String.prototype.htmlDecode =function()
     {

        text = this;
        
        text = text.replace(/&amp;/g, 
    "&") ;
        text = text.replace(/&quot;/g, 
    """) ;
        text 
    = text.replace(/&lt;/g,  "<") ;
        text 
    = text.replace(/&gt;/g, ">") ;
        text 
    = text.replace(/&#39;/g, "'") ;
        
    return text ;
    }



    //字符串方法重构, 是否包含
    String.prototype.Contains=function(A)
    {
        
    return (this.indexOf(A)>-1);
    }
    ;

    //字符串方法重构, 是否相等,已被扩展为是否在数组中。
    String.prototype.Equals=function()
    {
        
    var A=arguments;
         
    if (A.length==1&&A[0].pop) A=A[0];
         
    for (    var i=0; i<A.length; i++)
         

              
    if (this==A[i])
             
    return true;
         }
    ;
        
    return false;
    }
    ;


    //不区分大小写相等判断.
    String.prototype.IEquals=function()
    {
        
    var A=this.toUpperCase();
        
    var B=arguments;
        
    if (B.length==1&&B[0].pop) 
          B
    =B[0];
        
    for (var i=0;i<B.length;    i++)
        
    {
            
    if  (A==B[i].toUpperCase() ) return true;
        }
    ;
        
    return false;
    }
    ;

    //全部替换.
    String.prototype.ReplaceAll=function(A,B)
    {
        
    var C=this;
        
    for (var i=0;i<A.length;i++)
       
    {
           C
    =C.replace(A[i],B[i]);
       }
    ;
       
    return C;
    }
    ;



    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /******************************************************************************************************************/
    /////////////////////////////////////字符串表单正则验证处理。////////////////////////////////////////////////////////
    /*
    *Email : /^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$/,
    Phone : /^(((d{2,3}))|(d{3}-))?((0d{2,3})|0d{2,3}-)?[1-9]d{6,7}(-d{1,4})?$/,
    Mobile : /^(((d{2,3}))|(d{3}-))?13d{9}$/,
    Url : /^http://[A-Za-z0-9]+.[A-Za-z0-9]+[/=?%-&_~`@[]':+!]*([^""])*$/,
    IdCard : /^d{15}(d{2}[A-Za-z0-9])?$/,
    Currency : /^d+(.d+)?$/,
    Number : /^d+$/,
    Zip : /^[1-9]d{5}$/,
    QQ : /^[1-9]d{4,8}$/,
    Integer : /^[-+]?d+$/,
    Double : /^[-+]?d+(.d+)?$/,
    English : /^[A-Za-z]+$/,
    Chinese : /^[Α-¥]+$/,
    Username : /^[a-z]w{3,}$/i,
    UnSafe : /^(([A-Z]*|[a-z]*|d*|[-_~!@#$%^&*.()[]{}?\/'"]*)|.{0,5})$|s/,
    Name : /^[一-龥w0-9_-]{3,11}$/i
    *
    */

    //是否为URL.
    String.prototype.isUrl=function()
    {
        
    var Url =  /^(http(s)?://)?[A-Za-z0-9]+.[A-Za-z0-9]+[/=?%-&_~`@[]':+!]*([^""])*$/;
        return Url.test(this)?true:false;
    }

    //是否为邮政编码.
    String.prototype.isZip = function ()
    {
        var Zip = /^[1-9]d{5}$/;
       return Zip.test(this)?true:false;     
    }

    //返回是否为英文。
    String.prototype.isEnglish = function ()
    {
        var English =     /^[A-Za-z]+$/;
        return English.test(this)?true:false;     
    }

    //返回是否为中文。
    String.prototype.isChinese  = function ()
    {
        var Chinese =     /^[Α-¥]+$/;
        return Chinese.test(this)?true:false;     
    }

    //返回是否为数字
    String.prototype.isNum = function ()
    {
        var Num =     /^d+$/;
        return Num.test(this)?true:false;     
    }

    //返回是否为整数.
    String.prototype.isInt = function ()
    {
        var Int =      /^[-+]?d+$/;
        return Int.test(this)?true:false;     
    }

    //验证是否为unsafe
    String.prototype.isUnsafe = function ()
    {
        var Unsafe = /^(([A-Z]*|[a-z]*|d*|[-_~!@#$%^&*.()[]{}?\/'"]*)|.{0,5})$|s/;
        return Unsafe.test(this)?true:false;     
    }


    //验证是否是QQ.
    String.prototype.isQQ = function ()
    {
        var QQ =     /^[1-9]d{4,8}$/;
        return QQ.test(this)?true:false;     
    }

    //验证邮件.
    String.prototype.isEmail=function()
    {
        var Email = /^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$/;
        return Email.test(this)?true:false;
    }

    //是否为手机。
    String.prototype.isMobile=function()
    {
            var Tel = /^(((d{2,3}))|(d{3}-))?((0d{2,3})|0d{2,3}-)?[1-9]d{6,7}(-d{1,4})?$/;
            return Tel.test(this)?true:false;
    };

    //验证电话号码的可用性。
    String.prototype.isPhone=function()
    {
            var Tel = /^(((d{2,3}))|(d{3}-))?((0d{2,3})|0d{2,3}-)?[1-9]d{6,7}(-d{1,4})?$/;
            return Tel.test(this)?true:false;
    };

    //是否为用户。 中英文,加下划加中划。
    String.prototype.isUser=function()
    {
            var Name = /^[一-龥w0-9_-]{4,16}$/i;
            return Name.test(this)?true:false;
    };

    String.prototype.isNick=function()
    {
            var Nick = /^[一-龥w0-9_-]{3,16}$/i;
            return Nick.test(this)?true:false;
    };

    //密码格式
    String.prototype.isPassword=function()
    {
            var Password = /^.{6,16}$/i;
            return Password.test(this)?true:false;
    };
    //答案格式
    String.prototype.isAnswer=function()
    {
            var Answer = /^.{6,16}$/i;
            return Answer.test(this)?true:false;
    };

    //是否为用户。 中英文,加下划加中划。
    String.prototype.isPic=function()
    {
        PicTypeString  = picType.join("|");
        Pic = /.(replacement)$/ig;
        Pic = Pic.toString().replace ( "replacement" , PicTypeString );
        
       document.getElementById( "prompt").innerHTML = Pic;
        return eval(Pic).test(this)?true:false;
       
    };
     

     

    相关的demo 的

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>

    <input type="button" value="清除样式"   onclick=" cleanStyle(  ) "/>
    <input type="button" value="转HTML码"    onclick=" htmlEncode(  ) "/>
    <input type="button" value="解HTML码"    onclick=" htmlDecode(  ) "/>
    <script src="/static/media/js/jquery.js"></script>
    <script src="../string2.js"></script>


    <script src="/global/config.js"></script>
    <script>
    //清除样式。
    function  cleanStyle()
    {
        str 
    = document.getElementById("xuxing").innerHTML;
        str 
    = str.cleanStyle(); //here to cleanStyle
        document.getElementById("xuxing").innerHTML = str;
    }


    //将html进行编码。
    function htmlEncode(){
        str 
    = document.getElementById("xuxing").innerHTML;
        str 
    = str.htmlEncode(); //here to cleanStyle
        document.getElementById("xuxing").innerHTML = str;
    }


    //解码为html.
    function htmlDecode(){
        str 
    = document.getElementById("xuxing").innerHTML;
        str 
    = str.htmlDecode(); //here to cleanStyle
        document.getElementById("xuxing").innerHTML = str;
    }


    //检查电话号码格式。
    function  checkPhone()
    {
        str 
    = document.getElementById("telePhone").value;
        
    if( str.isPhone() )
        
    {
           alert( 
    "电话格式正确。" );
        }

        
    else
        
    {
            alert( 
    "电话格式不正确。" );
        }

    }


    //用户名验证。
    function  checkUser()
    {
        str 
    = document.getElementById("username").value;
        
        
    if( str.isUser() )
        
    {
           alert( 
    "用户名格式正确。" );
        }

        
    else
        
    {
            alert( 
    "用户名格式不正确。" );
        }

    }



    //URL验证。
    function  checkUrl()
    {
        str 
    = document.getElementById("url").value;
        
        
    if( str.isUrl() )
        
    {
           alert( 
    "URL格式正确。" );
        }

        
    else
        
    {
            alert( 
    "URL格式不正确。" );
        }

    }

    //验证是否为数字
    function checkNum ()
    {

        str 
    = document.getElementById("number").value;
        
        
    if( str.isNum() )
        
    {
           alert( 
    "num格式正确。" );
        }

        
    else
        
    {
            alert( 
    "num格式不正确。" );
        }


    }


    //验证是否为中文