手把手教你常用的59个JS类方法( 二 )

15.checkLowercaseLetter判断是否全部是小写字母
/** *判断是否全部是小写字母 * @param {Number} data */export const checkLowercaseLetter = data =https://www.isolves.com/it/cxkf/yy/js/2020-05-11/> /^[a-z]+$/g.test(data)复制代码16.checkCapitalLetter判断是否是大写字母
/** *判断是否是大写字母 * @param {Number} data */export const checkCapitalLetter = data =https://www.isolves.com/it/cxkf/yy/js/2020-05-11/> /^[A-Z]+$/g.test(data)复制代码17.checkNumOrLetter判断是否是字母或数字
/** * 判断是否是字母或数字 * @param {Number || String} data字符或数字 */export const checkNumOrLetter = data =https://www.isolves.com/it/cxkf/yy/js/2020-05-11/> /^[0-9a-zA-Z]*$/g.test(data)复制代码判断是否是字母和数字的组合
/** * 判断是否是字母或数字 * @param {Number || String} data字符或数字 */export const checkNumAndLetter = data =https://www.isolves.com/it/cxkf/yy/js/2020-05-11/> /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,15}$/g.test(data)复制代码18.checkChinese判断是否是中文
/** * 判断是否是中文 * @param {String} data中文 */export const checkChinese = data =https://www.isolves.com/it/cxkf/yy/js/2020-05-11/> /^[/u4E00-/u9FA5]+$/g.test(data)复制代码19.checkChineseNumberLettter判断是否是中文 , 数字或字母
export const checkChineseNumberLettter = data =https://www.isolves.com/it/cxkf/yy/js/2020-05-11/> /^[a-zA-Z0-9/u4e00-/u9fa5]+$/g.test(data)复制代码20.checkEmail判断是否是邮箱地址
/** * 判断是否是邮箱地址 * @param {String} data */export const checkEmail = data =https://www.isolves.com/it/cxkf/yy/js/2020-05-11/> {const reg = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/gif (reg.test(data)) return true}复制代码21.checkTelphone判断是否是手机号
/** * 判断是否是手机号 , 只要是13,14,15,16,17,18,19开头即可 * @param {String} data */export const checkTelphone = data =https://www.isolves.com/it/cxkf/yy/js/2020-05-11/> {const reg = /^((+|00)86)?1[3-9]d{9}$/gif (reg.test(data)) return true}复制代码22.checkUrl判断是否是正确的网址
/** * 判断是否是正确的网址 * @param {String} url 网址 */export const checkUrl = url => {const a = document.createElement('a')a.href = https://www.isolves.com/it/cxkf/yy/js/2020-05-11/urlreturn [/^(http|https):$/.test(a.protocol),a.host,a.pathname !== url,a.pathname !== `/${url}`].find(x => !x) === undefined}复制代码client23.checkBrowser/** * 判断是浏览器内核 */export const checkBrowser = () => {const u = navigator.userAgent;const obj = {trident: u.indexOf("Trident") > -1, //IE内核presto: u.indexOf("Presto") > -1, //opera内核webKit: u.indexOf("AppleWebKit") > -1, //苹果、谷歌内核gecko: u.indexOf("Gecko") > -1 && u.indexOf("Khtml") == -1, //火狐内核}return Object.keys(obj)[Object.values(obj).indexOf(true)]};复制代码24.checkIOSAndroidIpad判断是终端类型,值有ios,android,iPad
/** * 判断是终端类型,值有ios,android,iPad */export const checkIosAndroidIpad = () => {const u = navigator.userAgent;const obj = {ios: !!u.match(/(i[^;]+;( U;)? CPU.+mac OS X/), //ios终端android: u.indexOf("Android") > -1 || u.indexOf("linux") > -1, //android终端或者uc浏览器iPad: u.indexOf("iPad") > -1, //是否iPad}return Object.keys(obj)[Object.values(obj).indexOf(true)]};复制代码25.checkWeixinQqUc判断是否是微信,qq 或 uc
/** * 判断是否是微信,qq 或 uc */export const checkWeixinQqUc = () => {const u = navigator.userAgent;const obj = {weixin: u.indexOf("MicroMessenger") > -1, //是否微信qq: u.match(/QQ/i) == "qq"&&!u.indexOf('MQQBrowser') > -1, //是否QQuc: u.indexOf('UCBrowser') > -1}return Object.keys(obj)[Object.values(obj).indexOf(true)]};复制代码26.checkIsiphoneX检查是否是 IphoneX
/** * 检查是否是 IphoneX */export const checkIsIphoneX = () => {const u = navigator.userAgent;const isIOS = !!u.match(/(i[^;]+;( U;)? CPU.+Mac OS X/);if (isIOS && screen.height >= 812) {return true;}};复制代码file27.fileFormatSize格式化文件单位
/** * 格式化文件单位 * @param {String || Number} size文件大小(kb) */export const fileFormatSize = size => {var ivar unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']for (i = 0; i < unit.length && size >= 1024; i++) {size /= 1024}return (Math.round(size * 100) / 100 || 0) + unit[i]}复制代码obj28.objIsEqual判断两个对象是否相等,目前只支持对象值为简单数据类型的判断


推荐阅读