前端常用的js函数方法
程序员文章站
2022-06-15 15:16:15
目录1.邮箱2.手机号码3.电话号码4.是否url地址5.是否字符串6.是否数字7.是否boolean8.是否函数9.是否为null10.是否undefined11.是否对象12.是否数组13.是否时...
1.邮箱
export const isemail = (e) => { return /^([a-za-z0-9_-])+@([a-za-z0-9_-])+((.[a-za-z0-9_-]{2,3}){1,2})$/.test(e) }
2.手机号码
export const ismobile = (e) => { return /^1[0-9]{10}$/.test(e) }
3.电话号码
export const isphone = (e) =>{ return /^([0-9]{3,4}-)?[0-9]{7,8}$/.test(e) }
4.是否url地址
export const isurl = (e) => { return /^http[s]?:\/\/.*/.test(e) }
5.是否字符串
export const isnumber = (e) =>{ return object.prototype.tostring.call(e).slice(8,-1) === 'string' }
6.是否数字
export const isnumber = (e) =>{ return object.prototype.tostring.call(e).slice(8,-1) ==='number' }
7.是否boolean
export const isboolean = (e) =>{ return object.prototype.tostring.call(e).slice(8,-1) ==='boolean' }
8.是否函数
export const isfunction = (e) =>{ return object.prototype.tostring.call(e).slice(8,-1) === 'function' }
9.是否为null
export const isnull = (e) =>{ return object.prototype.tostring.call(e).slice(8,-1)==='null' }
10.是否undefined
export const isundefined = (e) =>{ return object.prototype.tostring.call(e).slice(8,-1)==='undefined' }
11.是否对象
export const isobject = (e) =>{ return object.prototype.tostring.call(e).slice(8,-1) === 'object' }
12.是否数组
export const isarray = (e) =>{ return object.prototype.tostring.call(e).slice(8,-1)==='array' }
13.是否时间
export const isdate = (e) =>{ return object.prototype.tostring.call(e).slice(8,-1)==='date' }
14.是否正则
export const isregexp = (e) =>{ return object.prototype.tostring.call(e).slice(8,-1)==='regexp' }
15.是否错误对象
export const iserror = (e) =>{ return object.prototype.tostring.call(e).slice(8,-1)==='error' }
16.是否symbol函数
export const issymbol = (e) =>{ return object.prototype.tostring.call(e).slice(8,-1)==='symbol' }
17.是否promise对象
export const ispromise = (e) =>{ return object.prototype.tostring.call(e).slice(8,-1)==='promise' }
18.是否set对象
export const isset = (e) =>{ return object.prototype.tostring.call(e).slice(8,-1) ==='set' } export const us = navigator.useragent.tolowercase();
19.是否是微信浏览器
export const isweixin = () =>{ return ua.match(/micromessenger/i) == 'micromessenger' }
20.是否是移动端
export const isdevicemobile =()=>{ return /android|webos|iphone|ipod|balckberry/i.test(ua) }
到此这篇关于常用的js函数方法的文章就介绍到这了,更多相关常用的js函数内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
上一篇: 【题解】P1440 求m区间内的最小值
下一篇: 抖音星图任务怎么做(带你玩转抖音星图)