Blogger Information
Blog 6
fans 19
comment 0
visits 4782
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
分享原生JavaScript技巧大收集验证篇
听鱼说php教学博客
Original
719 people have browsed it

原生javascript判断是否为邮箱

function isEmail(str){

    var re=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/; 

        if (re.test(str) != true) {

                return false;

        }else{

                return true;

        }        

}


原生javascript判断是否有列表中的危险字符

function isValidReg(chars){

        var re=/<|>|\[|\]|\{|\}|『|』|※|○|●|◎|§|△|▲|☆|★|◇|◆|□|▼|㊣|﹋|⊕|⊙|〒|ㄅ|ㄆ|ㄇ|ㄈ|ㄉ|ㄊ|ㄋ|ㄌ|ㄍ|ㄎ|ㄏ|ㄐ|ㄑ|ㄒ|ㄓ|ㄔ|ㄕ|ㄖ|ㄗ|ㄘ|ㄙ|ㄚ|ㄛ|ㄜ|ㄝ|ㄞ|ㄟ|ㄢ|ㄣ|ㄤ|ㄥ|ㄦ|ㄧ|ㄨ|ㄩ|■|▄|▆|\*|@|#|\^|\\/;

        if (re.test( chars) == true) {

                return false;

        }else{

                return true;

        }        

}

原生javascript判断字符串是否大于规定的长度

function isValidLength(chars, len) {

        if (chars.length < len) {

                return false;

        }

        return true;

}

复制代码

74、原生javascript判断字符串是为网址不区分大小写

function isValidURL( chars ) {

        var re=/^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(\S+\.\S+)$/;

        if (!isNULL(chars)) {

                chars = jsTrim(chars);

                if (chars.match(re) == null)

                        return false;

                else

                        return true;

        }

        return false;

}


原生javascript判断字符串是否为小数

function isValidDecimal( chars ) {

        var re=/^\d*\.?\d{1,2}$/;

        if (chars.match(re) == null)

                return false;

        else

                return true;

}


原生javascript判断字符串是否为整数

function isNumber( chars ) {

        var re=/^\d*$/;

        if (chars.match(re) == null)

                return false;

        else

                return true;

}


原生javascript判断字符串是否为浮点数

function isFloat( str ) {

        for(i=0;i<str.length;i++)  {

           if ((str.charAt(i)<"0" || str.charAt(i)>"9")&& str.charAt(i) != '.'){

                        return false;

           }

        }

        return true;

}


原生javascript判断字符是否为A-Za-z英文字母

function isLetters( str ){

        var re=/^[A-Za-z]+$/;

        if (str.match(re) == null)

                return false;

        else

                return true;

}


原生javascript判断字符串是否邮政编码

function isValidPost( chars ) {

        var re=/^\d{6}$/;

        if (chars.match(re) == null)

                return false;

        else

                return true;

}


原生javascript判断字符是否空NULL

function isNULL( chars ) {

        if (chars == null)

                return true;

        if (jsTrim(chars).length==0)

                return true;

        return false;

}


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!