Commonly used js function methods in the front end

Commonly used js function methods in the front end

1. Email

export 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 number

export const isMobile = (e) => {
return /^1[0-9]{10}$/.test(e)
}


3. Phone number

export 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:
  • Summary of several common methods of defining functions in JS
  • Three common methods for automatically executing JS functions in web pages
  • Summary of common methods for automatic execution of javascript functions
  • Commonly used JavaScript function methods collected and sorted daily
  • Detailed explanation of common methods of js function calls

<<:  MYSQL Left Join optimization (10 seconds to 20 milliseconds)

>>:  Html sample code for reading and displaying pictures in a local folder

Recommend

How to configure MGR single master and multiple slaves in MySQL 8.0.15

1. Introduction MySQL Group Replication (MGR for ...

A Preliminary Study on JSBridge in Javascript

Table of contents The origin of JSBridge The bidi...

Example of how rem is adapted for mobile devices

Preface Review and summary of mobile terminal rem...

CSS achieves the effect of two elements blending (sticky effect)

I remember that a few years ago, there was an int...

How to implement Vue timer

This article example shares the specific code of ...

MySQL Server IO 100% Analysis and Optimization Solution

Preface During the stress test, if the most direc...

Detailed steps to deploy lnmp under Docker

Table of contents Pull a centos image Generate ng...

Some tips on deep optimization to improve website access speed

Some tips for deep optimization to improve websit...

MySQL 8.0.22 decompression version installation tutorial (for beginners only)

Table of contents 1. Resource download 2. Unzip t...

How to use CURRENT_TIMESTAMP in MySQL

Table of contents Use of CURRENT_TIMESTAMP timest...

A brief discussion on the Linux kernel's support for floating-point operations

Currently, most CPUs support floating-point units...

Detailed explanation of the principle and usage of MySQL stored procedures

This article uses examples to explain the princip...

Summarize several common ranking problems in MySQL

Preface: In some application scenarios, we often ...