You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.2 KiB

/**
* Created by PanJiaChen on 16/11/18.
*/
/**
* @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
}
export const validation = new Map([
['integer',/(^$)|^-?\d+$/],//整数
['date',/(^$)|(^\d{10})|(^\d{13})|(^((\d\d\d\d(.+)|\d\d(.+))?(0?[1-9](.+)|1[012](.+))?((0?[1-9]|[12]\d|3[01])(.+))?\s?)((0?[0-9]|1[0-9]|2[0-3])(.+))?((0?[0-9]|[1-5][0-9])(.+))?((0?[0-9]|[1-5][0-9])(.+))?)$/],
['email',/(^$)|^[^\s@]+@[^\s@]+\.[^\s@]+$/],
['isIdCard',/(^$)|(^([1-6][1-9]|50)\d{4}\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3})|(^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx])$/],
['isMobile',/(^$)|(^1[3456789]\d{9})|(^(0\d{2,3}(-)*)?\d{7})$/],
['numeric',/(^$)|^-?\d+(.\d+)?$/],
])
export const validationName = new Map([
['integer','整数'],//整数
['date','日期'],
['email','邮箱'],
['isIdCard','身份证号'],
['isMobile','手机号'],
['numeric','数字'],
])