fe-drone-ci/src/utils/validate.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-04-18 07:09:13 +00:00
/**
* Created by jiachenpan on 16/11/18.
*/
2017-08-22 06:26:19 +00:00
export function isvalidUsername(str) {
const valid_map = ['admin', 'editor']
2017-08-22 07:43:34 +00:00
return valid_map.indexOf(str.trim()) >= 0
2017-04-18 07:09:13 +00:00
}
/* 合法uri*/
export function validateURL(textval) {
2017-08-22 07:43:34 +00:00
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)
2017-04-18 07:09:13 +00:00
}
/* 小写字母*/
export function validateLowerCase(str) {
2017-08-22 07:43:34 +00:00
const reg = /^[a-z]+$/
return reg.test(str)
2017-04-18 07:09:13 +00:00
}
/* 大写字母*/
export function validateUpperCase(str) {
2017-08-22 07:43:34 +00:00
const reg = /^[A-Z]+$/
return reg.test(str)
2017-04-18 07:09:13 +00:00
}
/* 大小写字母*/
export function validatAlphabets(str) {
2017-08-22 07:43:34 +00:00
const reg = /^[A-Za-z]+$/
return reg.test(str)
2017-04-18 07:09:13 +00:00
}
2017-11-15 07:27:19 +00:00
/**
* validate email
* @param email
* @returns {boolean}
*/
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);
}