验证邮箱
export const isEmail = (s) => {
return /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(s)
}
手机号码
export const isMoblie = (s) => {
return /^1[0-9]{10}$/.test(s)
}
电话号码
export const isPhone = (s) => {
return /^([0-9]{3,4}-)?[0-9]{7,8}$/.test(s)
}
是否url地址
export const isURL = (s) => {
return /^http[s]?:\/\/.*/.test(s)
}
是否为某种JS基本类型
//是否字符串
export const isString = (s) => {
return Object.prototype.toString.call(s).slice(8, -1) === 'String'
}
//是否数字 'String' 替换成 'Number'
//是否boolean 'String' 替换成 'boolean'
//是否函数 'String' 替换成 'Function'
//是否null 'String' 替换成 'null'
//是否undefined 'String' 替换成 'undefined'
//是否对象 'String' 替换成 'Object'
//是否数组 'String' 替换成 'Array'
//是否时间 'String' 替换成 'Date'
//是否错误对象 'String' 替换成 'Error'
//是否Symbol函数 'String' 替换成 'Symbol'
//是否Promise对象 'String' 替换成 'Promise'
//是否Set对象 'String' 替换成 'Set'
是否是微信浏览器
export const ua = navigator.userAgent.toLowerCase();
export const isWeiXin = () => {
return ua.match(/microMessenger/i) == 'micromessenger'
}
是否是移动端
export const ua = navigator.userAgent.toLowerCase();
export const isDeviceMobile = () => {
return /android|webos|iphone|ipod|balckberry/i.test(ua)
}
是否是QQ浏览器
export const ua = navigator.userAgent.toLowerCase();
export const isQQBrowser = () => {
return !!ua.match(/mqqbrowser|qzone|qqbrowser|qbwebviewtype/i)
}
是否ios
export const isIos = () => {
var u = navigator.userAgent;
if (u.includes('Android') || u.includes('Linux')) { // 安卓手机
return false;
} else if (u.includes('iPhone')) { // 苹果手机
return true;
} else if (u.indexOf('iPad') > -1) { // iPad
return false;
} else if (u.indexOf('Windows Phone') > -1) { // winphone手机
return false;
} else {
return false;
}
}
摘抄原文
来自:思否,作者:vipbic
链接:https://segmentfault.com/a/1190000022736837