前端常用的js函數(shù)方法
更新時(shí)間:2021年12月30日 09:37:15 作者:漂流_Fpwz
這篇文章主要給大家分享的是常用的js函數(shù)的方法,告別搜索引擎的幫助,提高你的開(kāi)發(fā)效率,,需要的朋友可以參考一下,希望對(duì)你的學(xué)習(xí)有所幫助
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.手機(jī)號(hào)碼
export const isMobile = (e) => {
return /^1[0-9]{10}$/.test(e)
}
3.電話(huà)號(hào)碼
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.是否數(shù)字
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.是否函數(shù)
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.是否對(duì)象
export const isObject = (e) =>{
return Object.prototype.toString.call(e).slice(8,-1) === 'Object'
}
12.是否數(shù)組
export const isArray = (e) =>{
return Object.prototype.toString.call(e).slice(8,-1)==='Array'
}
13.是否時(shí)間
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.是否錯(cuò)誤對(duì)象
export const isError = (e) =>{
return Object.prototype.toString.call(e).slice(8,-1)==='Error'
}
16.是否Symbol函數(shù)
export const isSymbol = (e) =>{
return Object.prototype.toString.call(e).slice(8,-1)==='Symbol'
}
17.是否Promise對(duì)象
export const isPromise = (e) =>{
return Object.prototype.toString.call(e).slice(8,-1)==='Promise'
}
18.是否Set對(duì)象
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.是否是移動(dòng)端
export const isDeviceMobile =()=>{
return /android|webos|iphone|ipod|balckberry/i.test(ua)
}
到此這篇關(guān)于常用的js函數(shù)方法的文章就介紹到這了,更多相關(guān)常用的js函數(shù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
如何提高數(shù)據(jù)訪(fǎng)問(wèn)速度
本文主要介紹了提高數(shù)據(jù)訪(fǎng)問(wèn)速度的方法,具有很好的參考作用,需要的朋友一起來(lái)看下吧2016-12-12
js屏蔽鼠標(biāo)鍵盤(pán)(右鍵/Ctrl+N/Shift+F10/F11/F5刷新/退格鍵)
屏蔽鼠標(biāo)右鍵、Ctrl+N、Shift+F10、F11、F5刷新、退格鍵/Alt+ 方向鍵 →等等,太多了就不一一寫(xiě)來(lái)了感興趣的朋友可以了解下啊,希望本文對(duì)你有所幫助
2013-01-01
js實(shí)現(xiàn)電燈開(kāi)關(guān)效果
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)電燈開(kāi)關(guān)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
2021-01-01
Openlayers實(shí)現(xiàn)測(cè)量功能
這篇文章主要為大家詳細(xì)介紹了Openlayers實(shí)現(xiàn)測(cè)量功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
2020-09-09 
