工具类

作者: 糖心儿的记录 | 来源:发表于2021-04-01 15:12 被阅读0次

    1.邮箱

    export const isEmail = (s) => {
        return /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(s)
    }
    

    2.手机号码

    export const isMobile =(number)=>{
        return /^1[0-9]{10}$/.test(number)
    }
    

    3.电话号码

    export const isPhone = (s) => {
        return /^([0-9]{3,4}-)?[0-9]{7,8}$/.test(s)
    }
    

    4.是否url地址

    export const isURL = (s) => {
        return /^http[s]?:\/\/.*/.test(s)
    }
    

    5.是否字符串 ==slice(8, -1)代表从第8个位置开始取,取到倒数第一个,但不包括最后一个==

    export const isString = (o) => {
        return Object.prototype.toString.call(o).slice(8, -1) === 'String'
    }
    

    6.是否数字

    export const isNumber = (o) => {
        return Object.prototype.toString.call(o).slice(8, -1) === 'Number'
    }
    

    7.是否boolean

    export const isBoolean = (o) => {
        return Object.prototype.toString.call(o).slice(8, -1) === 'Boolean'
    }
    

    8.是否函数

    export const isFunction = (o) => {
        return Object.prototype.toString.call(o).slice(8, -1) === 'Function'
    }
    

    9.是否为null

    export const isNull = (o) => {
        return Object.prototype.toString.call(o).slice(8, -1) === 'Null'
    }
    

    10.是否对象

    export const isObj = (o) => {
        return Object.prototype.toString.call(o).slice(8, -1) === 'Object'
    }
    

    11.是否数组

    export const isArray = (o) => {
        return Object.prototype.toString.call(o).slice(8, -1) === 'Array'
    }
    

    12.是否undefined

    export const isUndefined = (o) => {
        return Object.prototype.toString.call(o).slice(8, -1) === 'Undefined'
    }
    

    13.是否是微信浏览器

    export const isWeiXin = () => {
        return ua.match(/microMessenger/i) == 'micromessenger'
    }
    

    14、是否是移动端

    export const isDeviceMobile = () => {
        return /android|webos|iphone|ipod|balckberry/i.test(ua)
    }
    

    15、是否ios

    export const isIos = () => {
        var u = navigator.userAgent;
        if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {  //安卓手机
            return false
        } else if (u.indexOf('iPhone') > -1) {//苹果手机
            return true
        } else if (u.indexOf('iPad') > -1) {//iPad
            return false
        } else if (u.indexOf('Windows Phone') > -1) {//winphone手机
            return false
        } else {
            return false
        }
    }
    

    16、是否是PC端

    export const isPC = () => {
        var userAgentInfo = navigator.userAgent;
        var Agents = ["Android", "iPhone",
            "SymbianOS", "Windows Phone",
            "iPad", "iPod"];
        var flag = true;
        for (var v = 0; v < Agents.length; v++) {
            if (userAgentInfo.indexOf(Agents[v]) > 0) {
                flag = false;
                break;
            }
        }
        return flag;
    }
    

    17、

    相关文章

      网友评论

          本文标题:工具类

          本文链接:https://www.haomeiwen.com/subject/kuptkltx.html