mirror of https://gitee.com/pnoker/dc3-web.git
pull/1/head
parent
6d254b7bf2
commit
75696400f1
@ -0,0 +1,85 @@
|
||||
/**
|
||||
* 判断是否为Url
|
||||
* @param url
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isUrl(url) {
|
||||
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(url)
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为Email
|
||||
* @param email
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isEmail(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)
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为手机号码
|
||||
* @param phone
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isPhone(phone) {
|
||||
return /^1[0-9]{10}$/.test(phone)
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为整数
|
||||
* @param num
|
||||
* @param type
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isNum(num, type) {
|
||||
let regName = /[^\d.]/g;
|
||||
if (type == 1) {
|
||||
if (!regName.test(num)) return false;
|
||||
} else if (type == 2) {
|
||||
regName = /[^\d]/g;
|
||||
if (!regName.test(num)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为小数
|
||||
* @param num
|
||||
* @param type
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isNumord(num, type) {
|
||||
let regName = /[^\d.]/g;
|
||||
if (type == 1) {
|
||||
if (!regName.test(num)) return false;
|
||||
} else if (type == 2) {
|
||||
regName = /[^\d.]/g;
|
||||
if (!regName.test(num)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为空
|
||||
* @param val
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isNull(val) {
|
||||
if (typeof val == 'boolean') {
|
||||
return false;
|
||||
}
|
||||
if (typeof val == 'number') {
|
||||
return false;
|
||||
}
|
||||
if (val instanceof Array) {
|
||||
if (val.length === 0) return true;
|
||||
} else if (val instanceof Object) {
|
||||
if (JSON.stringify(val) === '{}') return true;
|
||||
} else {
|
||||
if (val === 'null' || val == null || val === 'undefined' || val === undefined || val === '') return true;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
Loading…
Reference in new issue