前端常用的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函數內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!