/**
*
* 过滤特殊字符
*/
export var checkObject = function () {
return {
//过滤特殊字符
stripscript: function (s) {
var pattern = new RegExp("[` ~!@#$^&*()=|{}':;',\[\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")
var rs = "";
for (var i = 0; i < s.length; i++) {
rs = rs + s.substr(i, 1).replace(pattern, '');
}
return rs;
},
//验证邮箱
checkEmail: function (value) {
let reg = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$/;
return reg.test(value) ? false : true
},
//验证密码
checkPassword: function (value) {
let reg = /^[a-zA-Z]w{5,19}$/;
return reg.test(value) ? false : true
},
//验证验证码
checkCode: function (value) {
let reg = /^[a-zA-Z0-9]{6}$/;
return reg.test(value) ? false : true
}
}
}
var validate = checkObeject();
validate.stripscript()
validate.checkEmail()
validate.checkPassword()
validate.checkCode()