美文网首页ReactNative
ReactNative工具类

ReactNative工具类

作者: WindFlyCloud | 来源:发表于2019-03-26 17:49 被阅读0次
    判断输入内容是否为空
        /**
         * 是否为空
         * @param text
         * @returns {boolean}
         */
        static isTextEmpty(text) {
            if (text==undefined || text == null || text.trim() == '') {
                return true;
            }
            return false;
        }
    
    判断对象是否为undefined 或者null
        /**
         * obj是否为空
         * @param object
         * @returns {boolean}
         */
        static isNull(object) {
            if (object == undefined || object == null) {
                return true;
            }
            return false;
        }
    
    验证手机号
       /**
         * 验证是否为手机号
         * @param {*} str
         */
        static isPhoneAvailable(str) {
            let myreg = /^(13[0-9]|14[5-9]|15[012356789]|16[0-8]|17[0-8]|18[0-9]|19[0-9])[0-9]{8}$/;  ;
            if (this.isTextEmpty(str)) {
                return false;
            } else if (!myreg.test(str)) {
                return false;
            } else {
                return true;
            }
        }
    
    获取当前时间的字符串
        /**
         * 获取当前时间的字符串
         * @param {时间戳}  
         */
        static getCurrentTimeStr() {
            var date = new Date();
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            m = m < 10 ? ('0' + m) : m;
            var d = date.getDate();
            d = d < 10 ? ('0' + d) : d;
            var h = date.getHours();
            h = h < 10 ? ('0' + h) : h;
            var minute = date.getMinutes();
            var second = date.getSeconds();
            minute = minute < 10 ? ('0' + minute) : minute;
            second = second < 10 ? ('0' + second) : second;
            return y + '' + m + '' +  d + '' + h + '' + minute + '' + second;
        };
    
    判断是否是表情符号
       /**
         * 判断是否是表情符号
         * @param {value值}  
         */
        static isEmojiCharacterInString(substring) {
            for ( var i = 0; i < substring.length; i++) {
                var hs =substring.charCodeAt(i);
                if (0xd800 <=hs && hs <=0xdbff) {
                    if (substring.length >1) {
                        var ls =substring.charCodeAt(i +1);
                        var uc = ((hs -0xd800) * 0x400) + (ls -0xdc00) + 0x10000;
                        if (0x1d000 <=uc && uc <=0x1f77f) {
                            return true;
                        }
                    }
                } else if (substring.length >1) {
                    var ls =substring.charCodeAt(i +1);
                    if (ls ==0x20e3) {
                        return true;
                    }
                } else {
                    if (0x2100 <=hs && hs <=0x27ff) {
                        return true;
                    } else if (0x2B05 <=hs && hs <=0x2b07) {
                        return true;
                    } else if (0x2934 <=hs && hs <=0x2935) {
                        return true;
                    } else if (0x3297 <=hs && hs <=0x3299) {
                        return true;
                    } else if (hs ==0xa9 || hs ==0xae || hs ==0x303d || hs ==0x3030
                        || hs == 0x2b55 ||hs == 0x2b1c ||hs == 0x2b1b
                        || hs == 0x2b50) {
                        return true;
                    }
                }
            }
          }
    

    相关文章

      网友评论

        本文标题:ReactNative工具类

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