|
@@ -2,87 +2,87 @@
|
|
|
* Created by jiachenpan on 16/11/18.
|
|
|
*/
|
|
|
|
|
|
-export function isExternal (path) {
|
|
|
+export function isExternal(path) {
|
|
|
return /^(https?:|mailto:|tel:)/.test(path)
|
|
|
}
|
|
|
|
|
|
-export function validPassword (str) {
|
|
|
+export function validPassword(str) {
|
|
|
const reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/
|
|
|
return reg.test(str)
|
|
|
}
|
|
|
|
|
|
-export function validUserVeriCode (str) {
|
|
|
+export function validUserVeriCode(str) {
|
|
|
const reg = /^\d{6}$/
|
|
|
return reg.test(str)
|
|
|
}
|
|
|
|
|
|
-export function validUserCellPhone (str) {
|
|
|
+export function validUserCellPhone(str) {
|
|
|
const reg = /^1[34578]\d{9}$/
|
|
|
return reg.test(str)
|
|
|
}
|
|
|
|
|
|
-export function validURL (url) {
|
|
|
+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)
|
|
|
}
|
|
|
|
|
|
-export function validLowerCase (str) {
|
|
|
+export function validLowerCase(str) {
|
|
|
const reg = /^[a-z]+$/
|
|
|
return reg.test(str)
|
|
|
}
|
|
|
|
|
|
-export function validUpperCase (str) {
|
|
|
+export function validUpperCase(str) {
|
|
|
const reg = /^[A-Z]+$/
|
|
|
return reg.test(str)
|
|
|
}
|
|
|
|
|
|
-export function validAlphabets (str) {
|
|
|
+export function validAlphabets(str) {
|
|
|
const reg = /^[A-Za-z]+$/
|
|
|
return reg.test(str)
|
|
|
}
|
|
|
|
|
|
-export function validEmail (email) {
|
|
|
+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)
|
|
|
}
|
|
|
|
|
|
-export function isString (str) {
|
|
|
+export function isString(str) {
|
|
|
if (typeof str === 'string' || str instanceof String) {
|
|
|
return true
|
|
|
}
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
-export function isArray (arg) {
|
|
|
+export function isArray(arg) {
|
|
|
if (typeof Array.isArray === 'undefined') {
|
|
|
return Object.prototype.toString.call(arg) === '[object Array]'
|
|
|
}
|
|
|
return Array.isArray(arg)
|
|
|
}
|
|
|
-export function isNumber (str) {
|
|
|
+export function isNumber(str) {
|
|
|
const reg = /^[0-9]+$/
|
|
|
return reg.test(str)
|
|
|
}
|
|
|
-export function cardId (str) {
|
|
|
+export function cardId(str) {
|
|
|
const reg = /^[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]$/
|
|
|
return reg.test(str)
|
|
|
}
|
|
|
// 正整数
|
|
|
-export function isNumberInteger (str) {
|
|
|
+export function isNumberInteger(str) {
|
|
|
const reg = /^[1-9]\d*$/
|
|
|
return reg.test(str)
|
|
|
}
|
|
|
// 其他电话
|
|
|
-export function otherPhone (str) {
|
|
|
+export function otherPhone(str) {
|
|
|
const reg = /^[0-9-\-;]*$/
|
|
|
return reg.test(str)
|
|
|
}
|
|
|
// 纯11位手机号码
|
|
|
-export function mobilePhone (str) {
|
|
|
+export function mobilePhone(str) {
|
|
|
const reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/
|
|
|
return reg.test(str)
|
|
|
}
|
|
|
-export function convertTwoDigitNumber (value) {
|
|
|
+export function convertTwoDigitNumber(value) {
|
|
|
return value.replace(/[^\d.]/g, '')
|
|
|
.replace(/\.{2,}/g, '.')
|
|
|
.replace('.', '$#$')
|
|
@@ -94,13 +94,13 @@ export function convertTwoDigitNumber (value) {
|
|
|
|
|
|
|
|
|
|
|
|
-export function isvalidUsername (str) {
|
|
|
+export function isvalidUsername(str) {
|
|
|
const valid_map = ['admin', 'editor']
|
|
|
return valid_map.indexOf(str.trim()) >= 0
|
|
|
}
|
|
|
|
|
|
/* 合法uri*/
|
|
|
-export function validateURL (textval) {
|
|
|
+export function validateURL(textval) {
|
|
|
const urlregex = /^(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 urlregex.test(textval)
|
|
|
}
|
|
@@ -108,7 +108,7 @@ export function validateURL (textval) {
|
|
|
* 邮箱
|
|
|
* @param {*} s
|
|
|
*/
|
|
|
-export function isEmail (s) {
|
|
|
+export function isEmail(s) {
|
|
|
return /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(s)
|
|
|
}
|
|
|
|
|
@@ -116,7 +116,7 @@ export function isEmail (s) {
|
|
|
* 手机号码
|
|
|
* @param {*} s
|
|
|
*/
|
|
|
-export function isMobile (s) {
|
|
|
+export function isMobile(s) {
|
|
|
return /^1[0-9]{10}$/.test(s)
|
|
|
}
|
|
|
|
|
@@ -124,7 +124,7 @@ export function isMobile (s) {
|
|
|
* 电话号码
|
|
|
* @param {*} s
|
|
|
*/
|
|
|
-export function isPhone (s) {
|
|
|
+export function isPhone(s) {
|
|
|
return /^([0-9]{3,4}-)?[0-9]{7,8}$/.test(s)
|
|
|
}
|
|
|
|
|
@@ -132,24 +132,24 @@ export function isPhone (s) {
|
|
|
* URL地址
|
|
|
* @param {*} s
|
|
|
*/
|
|
|
-export function isURL (s) {
|
|
|
+export function isURL(s) {
|
|
|
return /^http[s]?:\/\/.*/.test(s)
|
|
|
}
|
|
|
|
|
|
/* 小写字母*/
|
|
|
-export function validateLowerCase (str) {
|
|
|
+export function validateLowerCase(str) {
|
|
|
const reg = /^[a-z]+$/
|
|
|
return reg.test(str)
|
|
|
}
|
|
|
|
|
|
/* 大写字母*/
|
|
|
-export function validateUpperCase (str) {
|
|
|
+export function validateUpperCase(str) {
|
|
|
const reg = /^[A-Z]+$/
|
|
|
return reg.test(str)
|
|
|
}
|
|
|
|
|
|
/* 大小写字母*/
|
|
|
-export function validatAlphabets (str) {
|
|
|
+export function validatAlphabets(str) {
|
|
|
const reg = /^[A-Za-z]+$/
|
|
|
return reg.test(str)
|
|
|
}
|
|
@@ -174,7 +174,7 @@ export const vaildatePc = function () {
|
|
|
* @param email
|
|
|
* @returns {boolean}
|
|
|
*/
|
|
|
-export function validateEmail (email) {
|
|
|
+export function validateEmail(email) {
|
|
|
const re = /^(([^<>()\\[\]\\.,;:\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 re.test(email)
|
|
|
}
|
|
@@ -182,7 +182,7 @@ export function validateEmail (email) {
|
|
|
/**
|
|
|
* 判断身份证号码
|
|
|
*/
|
|
|
-export function cardid (code) {
|
|
|
+export function cardid(code) {
|
|
|
let list = [];
|
|
|
let result = true;
|
|
|
let msg = '';
|
|
@@ -266,7 +266,7 @@ export function cardid (code) {
|
|
|
/**
|
|
|
* 判断手机号码是否正确
|
|
|
*/
|
|
|
-export function isvalidatemobile (phone) {
|
|
|
+export function isvalidatemobile(phone) {
|
|
|
let list = [];
|
|
|
let result = true;
|
|
|
let msg = '';
|
|
@@ -292,7 +292,7 @@ export function isvalidatemobile (phone) {
|
|
|
/**
|
|
|
* 判断姓名是否正确
|
|
|
*/
|
|
|
-export function validatename (name) {
|
|
|
+export function validatename(name) {
|
|
|
var regName = /^[\u4e00-\u9fa5]{2,4}$/;
|
|
|
if (!regName.test(name)) return false;
|
|
|
return true;
|
|
@@ -300,7 +300,7 @@ export function validatename (name) {
|
|
|
/**
|
|
|
* 判断是否为整数
|
|
|
*/
|
|
|
-export function validatenum (num, type) {
|
|
|
+export function validatenum(num, type) {
|
|
|
let regName = /[^\d.]/g;
|
|
|
if (type == 1) {
|
|
|
if (!regName.test(num)) return false;
|
|
@@ -313,7 +313,7 @@ export function validatenum (num, type) {
|
|
|
/**
|
|
|
* 判断是否为小数
|
|
|
*/
|
|
|
-export function validatenumord (num, type) {
|
|
|
+export function validatenumord(num, type) {
|
|
|
let regName = /[^\d.]/g;
|
|
|
if (type == 1) {
|
|
|
if (!regName.test(num)) return false;
|
|
@@ -326,7 +326,7 @@ export function validatenumord (num, type) {
|
|
|
/**
|
|
|
* 判断是否为空
|
|
|
*/
|
|
|
-export function validatenull (val) {
|
|
|
+export function validatenull(val) {
|
|
|
if (typeof val == 'boolean') {
|
|
|
return false;
|
|
|
}
|