123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- /**
- * Created by PanJiaChen on 16/11/18.
- */
- /** https
- * @param {string} path
- * @returns {Boolean}
- */
- export function isExternal(path) {
- return /^(https?:|mailto:|tel:)/.test(path)
- }
- /** 用户名
- * @param {string} str
- * @returns {Boolean}
- */
- export function validUsername(str) {
- const valid_map = ['admin', 'editor']
- return valid_map.indexOf(str.trim()) >= 0
- }
- /** url
- * @param {string} url
- * @returns {Boolean}
- */
- export function validURL(url) {
- const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
- return reg.test(url)
- }
- /** 小写字母
- * @param {string} str
- * @returns {Boolean}
- */
- export function validLowerCase(str) {
- const reg = /^[a-z]+$/
- return reg.test(str)
- }
- /** 大写字母
- * @param {string} str
- * @returns {Boolean}
- */
- export function validUpperCase(str) {
- const reg = /^[A-Z]+$/
- return reg.test(str)
- }
- /** 字母
- * @param {string} str
- * @returns {Boolean}
- */
- export function validAlphabets(str) {
- const reg = /^[A-Za-z]+$/
- return reg.test(str)
- }
- /** 邮箱
- * @param {string} email
- * @returns {Boolean}
- */
- export function validEmail(email) {
- const reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
- return reg.test(email)
- }
- /** 字符串
- * @param {string} str
- * @returns {Boolean}
- */
- export function isString(str) {
- if (typeof str === 'string' || str instanceof String) {
- return true
- }
- return false
- }
- /** 数组
- * @param {Array} arg
- * @returns {Boolean}
- */
- export function isArray(arg) {
- if (typeof Array.isArray === 'undefined') {
- return Object.prototype.toString.call(arg) === '[object Array]'
- }
- return Array.isArray(arg)
- }
- /**
- * 邮箱
- * @param {*} s
- */
- export function isEmail(s) {
- return /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(
- s
- )
- }
- /**
- * 手机号码
- * @param {*} s
- */
- export function isMobile(s) {
- return /^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(s)
- }
- /**
- * 电话号码
- * @param {*} s
- */
- export function isPhone(s) {
- return /^([0-9]{3,4}-)?[0-9]{7,8}$/.test(s)
- }
- /**
- * 固定电话(支持分机)
- * @param {*} s
- */
- export function isExtension(s) {
- let type = true
- let arr = s.split('-')
- // console.log(arr);
- if (arr.length === 2 || arr.length === 3) {
- type = setF(arr)
- } else {
- type = false
- }
- // console.log('console' + type);
- return type
- ///0\d{2,3}-\d{7,8}(-\d{1,6})?/.test(s)
- }
- function setF(arr) {
- let type1 = true, type2 = true, type3 = true
- type1 = /0\d{2,3}?$/.test(arr[0])
- type2 = arr[1].length === 7 || arr[1].length === 8 ? /\d{7,8}$/.test(arr[1]) : false;
- if (arr.length === 3) {
- type3 = arr[2].length === 0 || arr[2].length > 6 ? false : /\d{1,6}$/.test(arr[2])
- }
- // console.log(type1, type2, type3);
- if (arr.length === 2) {
- return type1 && type2
- } else {
- return type1 && type2 && type3
- }
- }
- // (^(\d{11})$|^((\d{3}-)?\d{8}(-\d{1,4})?)$|^((\d{4}-)?\d{7}(-\d{1,4})?)$|^(\d{7,8})$)
- /**
- * 纳税人识别号
- * @param {*} s
- */
- export function isLicense(s) {
- return /[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}/.test(s)
- }
- /**
- * 身份证号码
- * @param {*} s
- */
- export function isIDentityCard(s) {
- return /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/.test(
- s
- )
- }
- /**
- * URL地址
- * @param {*} s
- */
- export function isURL(s) {
- return /^http[s]?:\/\/.*/.test(s)
- }
- /**
- * 汉语
- * @param {*} s
- */
- export function isChinese(s) {
- return /[\u4e00-\u9fa5]$/.test(s)
- }
- /**
- * 数字
- * @param {*} s
- */
- export function isnumber(s) {
- return /^[0-9]*$/.test(s)
- }
- /**
- * 数字或者带小数点的数字
- * @param {*} s
- */
- export function isnumber2(s) {
- return /(^[0-9]{1,2}$)|(^[0-9]{1,2}[\.]{1}[0-9]{1,2}$)/.test(s)
- }
- /**
- * 数字或者带小数点的数字 1,2,3位小数
- * @param {*} s
- */
- export function isnumber3(s) {
- return /^(([^0][0-9]+|0)\.([0-9]{1,3})$)|^([^0][0-9]+|0)$/.test(s)
- }
- /**
- * 数字字母
- * @param {*} s
- */
- export function isAlphanumeric(s) {
- return /^[0-9A-Za-z]*$/.test(s)
- }
- /**
- * 表情包
- * @param {*} s
- */
- export function isEmoticon(s) {
- const reg = /[^\u0020-\u007E\u00A0-\u00BE\u2E80-\uA4CF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF\u0080-\u009F\u2000-\u201f\u2026\u2022\u20ac\r\n]/g
- // console.log(reg.test(s));
- return reg.test(s)
- }
- /**
- * 判断是否为微信浏览器
- * @param {*} s
- */
- export function JudgeEnvironment() {
- const ua = navigator.userAgent.toLowerCase()
- let environment = ''
- const isWeixin = ua.indexOf('micromessenger') != -1
- if (isWeixin) {
- environment = 'Weixin'
- }
- const isWelink = ua.indexOf('huawei-anyoffice') != -1
- if (isWelink) {
- environment = 'Welink'
- }
- const isDingDing = ua.indexOf('dingtalk') != -1
- if (isDingDing) {
- environment = 'isDingDing'
- }
- if (environment === '') {
- environment = 'otherBrowser'
- }
- return environment
- }
- export function timestampToTime(timestamp) {
- const date = new Date(timestamp) // 时间戳为10位需*1000,时间戳为13位的话不需乘1000
- const Y = date.getFullYear() + '-'
- const M =
- (date.getMonth() + 1 < 10
- ? '0' + (date.getMonth() + 1)
- : date.getMonth() + 1) + '-'
- const D = date.getDate() + ' '
- let h = date.getHours()
- h = h < 10 ? `0${h}:` : h + ':'
- let m = date.getMinutes()
- m = m < 10 ? `0${m}:` : m + ':'
- let s = date.getSeconds()
- s = s < 10 ? `0${s}` : s
- return Y + M + D + h + m + s
- }
- export function isCreditCode(s) {
- const reg = /[^_IOZSVa-z\W]{2}\d{6}[^_IOZSVa-z\W]{10}$/g;
- return reg.test(s)
- }
|