耀极客论坛

 找回密码
 立即注册
查看: 1345|回复: 0

前端常用的js函数方法

[复制链接]

1630

主题

1517

回帖

22万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
229090
发表于 2022-5-7 01:08:29 | 显示全部楼层 |阅读模式
  这篇文章主要给大家分享的是常用的js函数的方法,告别搜索引擎的帮助,提高你的开发效率,,需要的朋友可以参考一下,希望对你的学习有所帮助

1.邮箱
  1. export const isEmail = (e) => {
  2. return /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(e)
  3. }
复制代码
2.手机号码
  1. export const isMobile = (e) => {
  2. return /^1[0-9]{10}$/.test(e)
  3. }
复制代码
3.电话号码
  1. export const isPhone = (e) =>{
  2. return /^([0-9]{3,4}-)?[0-9]{7,8}$/.test(e)
  3. }
复制代码
4.是否url地址
  1. export const isURL = (e) => {
  2. return /^http[s]?:\/\/.*/.test(e)
  3. }
复制代码
5.是否字符串
  1. export const isNumber = (e) =>{
  2. return Object.prototype.toString.call(e).slice(8,-1) === 'String'
  3. }
复制代码
6.是否数字
  1. export const isNumber = (e) =>{
  2. return Object.prototype.toString.call(e).slice(8,-1) ==='Number'
  3. }
复制代码
7.是否boolean
  1. export const isBoolean = (e) =>{
  2. return Object.prototype.toString.call(e).slice(8,-1) ==='Boolean'
  3. }
复制代码
8.是否函数
  1. export const isFunction = (e) =>{
  2. return Object.prototype.toString.call(e).slice(8,-1) === 'Function'
  3. }
复制代码
9.是否为null
  1. export const isNull = (e) =>{
  2. return Object.prototype.toString.call(e).slice(8,-1)==='Null'
  3. }
复制代码
10.是否undefined
  1. export const isUndefined = (e) =>{
  2. return Object.prototype.toString.call(e).slice(8,-1)==='Undefined'
  3. }
复制代码
11.是否对象
  1. export const isObject = (e) =>{
  2. return Object.prototype.toString.call(e).slice(8,-1) === 'Object'
  3. }
复制代码
12.是否数组
  1. export const isArray = (e) =>{
  2. return Object.prototype.toString.call(e).slice(8,-1)==='Array'
  3. }
复制代码
13.是否时间
  1. export const isDate = (e) =>{
  2. return Object.prototype.toString.call(e).slice(8,-1)==='Date'
  3. }
复制代码
14.是否正则
  1. export const isRegExp = (e) =>{
  2. return Object.prototype.toString.call(e).slice(8,-1)==='RegExp'
  3. }
复制代码
15.是否错误对象
  1. export const isError = (e) =>{
  2. return Object.prototype.toString.call(e).slice(8,-1)==='Error'
  3. }
复制代码
16.是否Symbol函数
  1. export const isSymbol = (e) =>{
  2. return Object.prototype.toString.call(e).slice(8,-1)==='Symbol'
  3. }
复制代码
17.是否Promise对象
  1. export const isPromise = (e) =>{
  2. return Object.prototype.toString.call(e).slice(8,-1)==='Promise'
  3. }
复制代码
18.是否Set对象
  1. export const isSet = (e) =>{
  2. return Object.prototype.toString.call(e).slice(8,-1) ==='Set'
  3. }
  4. export const us = navigator.userAgent.toLowerCase();
复制代码
19.是否是微信浏览器
  1. export const isWeiXin = () =>{
  2. return ua.match(/microMessenger/i) == 'micromessenger'
  3. }
复制代码
20.是否是移动端
  1. export const isDeviceMobile =()=>{
  2. return /android|webos|iphone|ipod|balckberry/i.test(ua)
  3. }
复制代码
  到此这篇关于常用的js函数方法的文章就介绍到这了,更多相关常用的js函数内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|耀极客论坛 ( 粤ICP备2022052845号-2 )|网站地图

GMT+8, 2023-3-24 15:11 , Processed in 0.067653 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表