전단 정규 표현 식 검증

3230 단어 정규 표현 식
/*******************************************

    :  

$.Validation("[email protected]", 1)

$.Length("    ",8)

*******************************************/



(function ($) {

    $.extend({

        Validation: function (strs, chkType) {//strs        ,chkType    (  regArr  )

            var reg = /^\w+([-\.]\w+)*@\w+([\.-]\w+)*\.\w{2,4}$/; //  (  )

            switch (chkType) {

                case 1: reg = /^\w+([-\.]\w+)*@\w+([\.-]\w+)*\.\w{2,4}$/; break;  //  

                case 2: reg = /^[0-9]+\.{0,1}[0-9]{0,2}$/; break; //      

                case 3: reg = /^[0-9]*$/; break; //      

                case 4: reg = /^\+?[1-9][0-9]*$/; break;  //          

                case 5: reg = /^[0-9]+(.[0-9]{2})?$/; break; //             

                case 6: reg = /^[A-Za-z]+$/; break; //     26           

                case 7: reg = /^[A-Z]+$/; break;  //     26             

                case 8: reg = /^[a-z]+$/; break; //     26             

                case 9: reg = /^[A-Za-z0-9]+$/; break; //        26           

                case 10: reg = /^\w+$/; break; //       、26                

                case 11: reg = /^[a-zA-Z]\w{5,17}$/; break;  //     ,   6~18  ,      、      

                case 12: reg = /[^%&,;=?$\\x22]+/; break;  //      ^%&,;=?$\"   

                case 13: reg = /^[\u4e00-\u9fa5]{0,}$/; break; //      

                case 14: reg = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+\..+$/; break; //     http://www.baidu.com

                case 15: reg = /^(0[0-9]{2})-\d{8}$|^(0[0-9]{3}-(\d{7,8}))$/; break; //    

                case 16: reg = /^([0-9]{11})?$/; break; //   

                case 17: reg = /^(\d{3,4}-)?\d{7,8}$/; break; //  

                case 18: reg = /^\d{5,11}$/; break; //QQ

                case 19: reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/; break; //MSN

                case 20: reg = /^\w+([-\.]\w+)*@(qq|sina|126|163)([\.-]\w+)*\.\w{2,4}$/; break; //    

                case 21: reg = /^[0-9]{6}$/; break; //  

            }

            return reg.test(strs);

        },

        Length: function (strs, num) {//          num  true,  false(          2,ASCII   1)

            var strNum = strs.len();

            if (strNum > num) {

                return false;

            }

            return true;

        },

        cutString: function (strs, num) { //    (  2   ,    1   )

            var strNum = strs.len();



            if (strNum > num) {

                var cutLength = 0; //     

                var charNum = 0;  //    

                var strsArry = strs.split('');

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

                    charNum += strsArry[i].len();

                    if (charNum > num) {

                        cutLength = i;

                        break;

                    }

                }

                return $.trim(strs).substring(0, cutLength);

            }

            return strs;

        }

    });

})(jQuery);



String.prototype.len = function () { return this.replace(/[^\x00-\xff]/g, "aa").length; }

좋은 웹페이지 즐겨찾기