1. Emailexport const isEmail = (e) => { return /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(e) } 2. Mobile phone numberexport const isMobile = (e) => { return /^1[0-9]{10}$/.test(e) } 3. Phone numberexport const isPhone = (e) => { return /^([0-9]{3,4}-)?[0-9]{7,8}$/.test(e) } 4. Is it a URL address?export const isURL = (e) => { return /^http[s]?:\/\/.*/.test(e) } 5. Is it a string?export const isNumber = (e) => { return Object.prototype.toString.call(e).slice(8,-1) === 'String' } 6. Is it digital?export const isNumber = (e) => { return Object.prototype.toString.call(e).slice(8,-1) === 'Number' } 7. Is it boolean?export const isBoolean = (e) => { return Object.prototype.toString.call(e).slice(8,-1) === 'Boolean' } 8. Is it a function?export const isFunction = (e) => { return Object.prototype.toString.call(e).slice(8,-1) === 'Function' } 9. Is it null?export const isNull = (e) => { return Object.prototype.toString.call(e).slice(8,-1) === 'Null' } 10. Is it undefined?export const isUndefined = (e) => { return Object.prototype.toString.call(e).slice(8,-1) === 'Undefined' } 11. Is it a target?export const isObject = (e) => { return Object.prototype.toString.call(e).slice(8,-1) === 'Object' } 12. Is it an array?export const isArray = (e) => { return Object.prototype.toString.call(e).slice(8,-1) === 'Array' } 13. Is it time?export const isDate = (e) => { return Object.prototype.toString.call(e).slice(8,-1)==='Date' } 14. Is it regular?export const isRegExp = (e) => { return Object.prototype.toString.call(e).slice(8,-1) === 'RegExp' } 15. Is it the wrong object?export const isError = (e) => { return Object.prototype.toString.call(e).slice(8,-1) === 'Error' } 16. Is it a Symbol function?export const isSymbol = (e) => { return Object.prototype.toString.call(e).slice(8,-1) === 'Symbol' } 17. Is it a Promise object?export const isPromise = (e) => { return Object.prototype.toString.call(e).slice(8,-1) === 'Promise' } 18. Is it a Set object?export const isSet = (e) => { return Object.prototype.toString.call(e).slice(8,-1) === 'Set' } export const us = navigator.userAgent.toLowerCase(); 19. Is it a WeChat browser?export const isWeiXin = () => { return ua.match(/microMessenger/i) == 'micromessenger' } 20. Is it a mobile terminal?export const isDeviceMobile =()=>{ return /android|webos|iphone|ipod|balckberry/i.test(ua) } This is the end of this article about commonly used js function methods. For more related commonly used js function content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: MYSQL Left Join optimization (10 seconds to 20 milliseconds)
>>: Html sample code for reading and displaying pictures in a local folder
1. Introduction MySQL Group Replication (MGR for ...
Table of contents The origin of JSBridge The bidi...
Preface Review and summary of mobile terminal rem...
I remember that a few years ago, there was an int...
This article example shares the specific code of ...
Preface During the stress test, if the most direc...
Table of contents Pull a centos image Generate ng...
Because we were going to build a website, in addi...
Some tips for deep optimization to improve websit...
Table of contents 1. Resource download 2. Unzip t...
Table of contents Use of CURRENT_TIMESTAMP timest...
Currently, most CPUs support floating-point units...
You may remember that in the past articles we hav...
This article uses examples to explain the princip...
Preface: In some application scenarios, we often ...