Commit 949cd1dc by txy

'提取校验逻辑'

parent 7d321a71
...@@ -100,103 +100,11 @@ function btnBindClick() { ...@@ -100,103 +100,11 @@ function btnBindClick() {
var addInput = JSON.parse(data.dataJson).addGroup var addInput = JSON.parse(data.dataJson).addGroup
var uploadImg = $('#act31419345204861 img') var uploadImg = $('#act31419345204861 img')
// 验证用户名 var flag = validateForm();
if (userName.attr('c_validateempty') == 'yes') { if(!flag) {
var userNameVal = userName.val() return false;
var userNameLen = userName.attr('c_len')
if (userNameVal == '') {
$.dialog({
type : 'tips',
autoClose : 3000,
infoText : '请输入参与者姓名'
});
return false
} else if (userNameVal.length > userNameLen) {
$.dialog({
type : 'tips',
autoClose : 3000,
infoText : '参与者姓名不能超过' + userNameLen + '个字'
});
return false
}
}
// 验证手机号
if (phonenum.attr('c_validateempty') == 'yes') {
var reg = /^1[3456789]\d{9}$/
var phonenumVal = phonenum.val()
var phonenumLen = phonenum.attr('c_len')
if (phonenumVal == '') {
$.dialog({
type : 'tips',
autoClose : 3000,
infoText : '请输入参与者手机号码'
});
return false
} else if (phonenumVal.length > phonenumLen) {
$.dialog({
type : 'tips',
autoClose : 3000,
infoText : '参与者手机号码不能超过' + phonenumLen + '个字'
});
return false
} else if (!reg.test(phonenumVal)) {
$.dialog({
type : 'tips',
autoClose : 3000,
infoText : '请输入正确的参与者手机号码'
});
return false
}
}
// 验证活动宣言
if (introDuce.attr('c_validateempty') == 'yes') {
var introDuceVal = introDuce.val()
var introDuceLen = introDuce.attr('c_len')
var introDuceName = introDuce.attr('c_name')
if (introDuceVal == '') {
$.dialog({
type : 'tips',
autoClose : 3000,
infoText : '请输入' + introDuceName
});
return false
} else if (introDuceVal.length > introDuceLen) {
$.dialog({
type : 'tips',
autoClose : 3000,
infoText : introDuceName + '不能超过' + introDuceLen + '个字'
});
return false
}
}
// 验证身份证
if (signInput.attr('c_validateempty') == 'yes') {
var signInputVal = signInput.val()
var signInputName = signInput.attr('c_name')
var signInputLen = signInput.attr('c_len')
if (signInputVal == '') {
$.dialog({
type : 'tips',
autoClose : 3000,
infoText : '请输入' + signInputName
});
return false
} else if (signInputVal.length > signInputLen) {
$.dialog({
type : 'tips',
autoClose : 3000,
infoText : signInputName + '不能超过' + signInputLen + '个字'
});
return false
} else if (!validateIDNumber(signInputVal)) {
$.dialog({
type : 'tips',
autoClose : 3000,
infoText : '请输入正确的' + signInputName
});
return false
}
} }
// 验证上传图片 // 验证上传图片
if (uploadImg.attr('src') == '') { if (uploadImg.attr('src') == '') {
$.dialog({ $.dialog({
...@@ -553,3 +461,103 @@ function validateIDNumber(card) { ...@@ -553,3 +461,103 @@ function validateIDNumber(card) {
} }
return true return true
} }
// 验证用户姓名
function validateUserName(userName) {
let state = false
if (userName !== '') {
let uName = userName.replace(/\s*/g, '')
var reg = /^(([a-zA-Z+\.??a-zA-Z+]{1,15}$)|([\u4e00-\u9fa5+?\u4e00-\u9fa5+]{1,15}$))/
if (!reg.test(uName)) {
state = false
} else {
state = true
}
}
return state
}
// 验证手机号
function validatePhone(phonenum) {
let state = false
if (phonenum !== '') {
var reg = /^1[3456789]\d{9}$/
if (!reg.test(phonenum)) {
state = false
} else {
state = true
}
}
return state
}
// 验证输入框
function validateInput($input) {
var c_len = $input.attr("c_len");
var c_validateempty = $input.attr("c_validateempty");
var c_validate = $input.attr("c_validate");
var c_name = $input.attr('c_name');
var _value = $input.val();
// 为空校验
if (c_validateempty == 'yes' && _value == '') {
$.dialog({
type : 'tips',
autoClose : 3000,
infoText : c_name + '不能为空'
});
return false;
}
// 长度校验
if (_value.length > c_len) {
$.dialog({
type : 'tips',
autoClose : 3000,
infoText : c_name + '不能超过' + c_len + '个字'
});
return false;
}
// 规则校验 c_validate = phone,idcard,username三种类型
if (c_validate !== ''){
if(c_validate === 'phone' && !validatePhone(_value)) {// 手机校验
$.dialog({
type : 'tips',
autoClose : 3000,
infoText : '手机号格式错误'
});
return false;
} else if(c_validate === 'idcard' && !validateIDNumber(_value)){// 身份证校验
$.dialog({
type : 'tips',
autoClose : 3000,
infoText : '身份证格式错误'
});
return false;
} else if(c_validate === 'username' && !validateUserName(_value)){// 用户名称校验
$.dialog({
type : 'tips',
autoClose : 3000,
infoText : '用户名格式错误,请输入中文或者英文'
});
return false;
}
}
return true;
}
// 验证表单输入框
function validateForm() {
var inputs = $('.sign-form .form-input-group-inner input');
var flag = true;
for(var k =0 ;k < inputs.length; k++){
flag = validateInput(inputs.eq(k));
if(!flag){
break;
}
}
return flag
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment