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

Steps for importing tens of millions of data into MySQL using .Net Core

Table of contents Preliminary preparation Impleme...

Solution to the problem of passing values ​​between html pages

The first time I used the essay, I felt quite awkw...

A brief analysis of React's understanding of state

How to define complex components (class component...

JavaScript to filter arrays

This article example shares the specific code for...

Tutorial on installing nginx in Linux environment

Table of contents 1. Install the required environ...

jQuery implements nested tab function

This article example shares the specific code of ...

Vue ElementUI implements asynchronous loading tree

This article example shares the specific code of ...

Key points for writing content of HTML web page META tags

The META tag is an auxiliary tag in the head area...

How to configure pseudo-static and client-adaptive Nginx

The backend uses the thinkphp3.2.3 framework. If ...

Should I use distinct or group by to remove duplicates in MySQL?

Preface About the performance comparison between ...

Docker container operation instructions summary and detailed explanation

1. Create and run a container docker run -it --rm...

Two ways to implement square div using CSS

Goal: Create a square whose side length is equal ...