|
这篇文章主要给大家分享的是常用的js函数的方法,告别搜索引擎的帮助,提高你的开发效率,,需要的朋友可以参考一下,希望对你的学习有所帮助
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函数内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

|
|