常用的javascript正则应用

2011-01-18 16:24:37 by 【6yang】, 131 visits, 收藏 | 返回

(function(a) {
    a.func = {
        isStrictMode: function() {
            return document.compatMode != "BackCompat"
        },
        pageWidth: function() {
            return this.isStrictMode() ? Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth) : Math.max(document.body.scrollWidth, document.body.clientWidth)
        },
        pageHeight: function() {
            return this.isStrictMode() ? Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) : Math.max(document.body.scrollHeight, document.body.clientHeight)
        },
        winWidth: function() {
            return this.isStrictMode() ?
            document.documentElement.clientWidth: document.body.clientWidth
        },
        winHeight: function() {
            return this.isStrictMode() ? document.documentElement.clientHeight: document.body.clientHeight
        },
        isBlank: function(c) {
            return /^s*$/.test(c)
        },
        isEmail: function(c) {
            return /^[A-Z_a-z0-9-.]+@([A-Z_a-z0-9-]+.)+[a-z0-9A-Z]{2,4}$/.test(c)
        },
        isNumber: function(c) {
            return /^d+$/.test(c)
        },
        isString: function(c) {
            return typeof c == "string"
        },
        isMobile: function(c) {
            return /^(((d{2,3}))|(d{3}-))?((1[345]d{9})|(18d{9}))$/.test(c)
        },
        isZip: function(c) {
            return /^[1-9]d{5}$/.test(c)
        },
        strLen: function(c) {
            function d(g) {
                return /[u4E00-uFA29]|[uE7C7-uE7F3]/.test(g)
            }
            var e = 0;
            for (i = 0; i < c.length; i++) e += d(c.charAt(i)) == true ? 2: 1;
            return e
        }
    }
})(jQuery);

分享到:
share

    图片原图

    loading

    loading