填空题多种数据类型验证设置

This commit is contained in:
keyuan 2021-04-25 22:55:36 +08:00
parent 2724026d3d
commit c0f7c1d15e
5 changed files with 153 additions and 9 deletions

View File

@ -351,13 +351,13 @@ label.error{
<%-- <input type="text" name="qu_${en.quType }_${en.id }" style="width:200px;padding:5px;" class="inputSytle_1 fillblankInput"> --%>
<c:choose>
<c:when test="${en.checkType eq 'DATE'}">
<input type="text" name="qu_${en.quType }_${en.id }" style="width: 300px;padding: 6px 10px 5px;border: 1px solid #83ABCB;outline: none;" class=" fillblankInput" >
<input type="text" name="qu_${en.quType }_${en.id }" style="width: 300px;padding: 6px 10px 5px;border: 1px solid #83ABCB;outline: none;" class=" fillblankInput" placeholder="请选择日期时间" >
</c:when>
<c:when test="${en.answerInputRow > 1 }">
<textarea name="qu_${en.quType }_${en.id }" rows="${en.answerInputRow }" style="width:${empty(en.answerInputWidth)?'300':en.answerInputWidth}px;"class="inputSytle_2 fillblankInput" ></textarea>
</c:when>
<c:otherwise>
<input type="text" name="qu_${en.quType }_${en.id }" style="width:${empty(en.answerInputWidth)?'300':en.answerInputWidth}px;" class="inputSytle_1 fillblankInput" >
<input type="text" name="qu_${en.quType }_${en.id }" style="width:${empty(en.answerInputWidth)?'300':en.answerInputWidth}px;" class="inputSytle_1 fillblankInput" placeholder="请输入${(en.checkType eq null || en.checkType eq 'NO') ? '内容':en.checkType.name},为${en.isRequired eq 0?'选填':'必填'}" >
</c:otherwise>
</c:choose>
<div class="dwComEditMenuBtn" ></div>

View File

@ -2387,6 +2387,7 @@
<option value="NUM">数字</option>
<option value="DIGITS">整数</option>
<option value="TELE_PHONE_NUM">手机或电话</option>
<option value="DATE">日期</option>
<option value="ZIPCODE">邮政编码</option>
<option value="TELENUM">电话号码</option>
<option value="PHONENUM">手机号码</option>

View File

@ -36,3 +36,102 @@ function bindDateEvent(){
});
});
}
function checkoutData(checkType, value) {
var validateStatus = true;
if(value.length<=0){
validateStatus = false;
}
if (checkType == "NO") {
if(value.length<=0){
validateStatus = false;
}
}else if (checkType == "EMAIL") {
var __email = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
if (!__email.test(value)) {
validateStatus = false;
}
} else if (checkType == "UNSTRCN") {
var __cn = /^[\u3220-\uFA29]+$/;
if (__cn.test(value)) {
validateStatus = false;
}
} else if (checkType == "STRCN") {
var __cn = /^[\u3220-\uFA29]+$/;
if (!__cn.test(value)) {
validateStatus = false;
}
} else if (checkType == "NUM") {
// "number[/[+|-][int|integer|float|double|money|{位数正则}.{位数正则}]]"
// var __regex = /^\d+(\.\d+)?$/;
var __regex = /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/;
if (!__regex.test(value)) {
validateStatus = false;
}
} else if (checkType == "DIGITS") {
var __regex = /^\d+$/;
if (!__regex.test(value)) {
validateStatus = false;
}
} else if (checkType == "TELENUM") {
var tel = /^\d{3,4}-{1}\d{7,9}-?\d{1,6}$/;
var tel400800 = /^(400{1}-?[0-9]{3}-?[0-9]{4})|(800{1}-?[0-9]{3}-?[0-9]{4})$/
if (!(tel.test(value) || tel400800.test(value))) {
validateStatus = false;
}
} else if (checkType == "PHONENUM") {
var length = value.length;
var mobile = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
if (!(length == 11 && mobile.test(value))) {
validateStatus = false;
}
} else if (checkType == "TELE_PHONE_NUM") {
var mobile = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
var tel = /^\d{3,4}-{1}\d{7,9}-?\d{1,6}$/;
var tel400800 = /^(400{1}-?[0-9]{3}-?[0-9]{4})|(800{1}-?[0-9]{3}-?[0-9]{4})$/
if (!(tel400800.test(value) || tel.test(value) || mobile.test(value))) {
validateStatus = false;
}
} else if (checkType == "DATE") {
//日期的正则表达式
/*var reg1 = /^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/;//2014-01-01
var regExp1 = new RegExp(reg1);
var reg2 = /^(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d$/;//12:00:00
var regExp2 = new RegExp(reg2);
var reg3 = /^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s+(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d$/;//2014-01-01 12:00:00
var regExp3 = new RegExp(reg3);
if(!(regExp1.test(value) || regExp3.test(value))){
// alert("日期格式不正确正确格式为2014-01-01");
errorType = "DATE";
validateStatus = false;
}*/
if (/Invalid|NaN/.test(new Date(value).toString())) {
validateStatus = false;
}
} else if (checkType == "IDENTCODE") {
var check = /^\d{15}|(\d{17}(\d|x|X))$/.test(value);
if (!(check && (value.length == 15 || value.length == 18))) {
validateStatus = false;
}
} else if (checkType == "ZIPCODE") {
var tel = /^[0-9]{6}$/;
if (!tel.test(value)) {
validateStatus = false;
}
} else if (checkType == "URL"){
var strRegex = /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i;
if (!strRegex.test(value)) {
validateStatus = false;
}
}
return validateStatus;
}

View File

@ -243,7 +243,7 @@ $(document).ready(function(){
var isRequired=quItemBody.find(".isRequired").val();
var validateStatus=false;
var checkType = "";
if(isRequired==="0"){
validateStatus = true;
return true;
@ -264,7 +264,12 @@ $(document).ready(function(){
}else if(quType==="CHECKBOX"){
validateStatus=quItemBody.find("input[type='checkbox']:checked")[0];
}else if(quType==="FILLBLANK"){
validateStatus=quItemBody.find(".fillblankInput").val()!="";
var value = quItemBody.find(".fillblankInput").val();
validateStatus=value!="";
checkType = quItemBody.find(".checkType").val();
if(validateStatus){
validateStatus = checkoutData(checkType, value);
}
}else if(quType==="ORDERQU"){
//quItemBody.find(".quOrderByLeftUl label");
validateStatus=!quItemBody.find(".quOrderByLeftUl label")[0];
@ -320,8 +325,39 @@ $(document).ready(function(){
if(validateStatus){
quItemBody.find(".errorItem").remove();
}else{
if(isSubForm && !quItemBody.find(".errorItem")[0]){
if(isSubForm){
if(quItemBody.find(".errorItem")[0]){
quItemBody.find(".errorItem").remove();
}
var errorHtml="<div class=\"errorItem\"><label for=\"\" class=\"error\">请检查题目答案,为必答项!</label></div>";
if(checkType=="EMAIL"){
errorHtml="<div class=\"errorItem\"><label for=\"\" class=\"error\">请输入Email为必答项</label></div>";
}else if(checkType=="UNSTRCN"){
errorHtml="<div class=\"errorItem\"><label for=\"\" class=\"error\">请输入非中文字符,为必答项!</label></div>";
}else if(checkType=="STRCN"){
errorHtml="<div class=\"errorItem\"><label for=\"\" class=\"error\">请输入中文字符,为必答项!</label></div>";
}else if(checkType=="NUM"){
errorHtml="<div class=\"errorItem\"><label for=\"\" class=\"error\">请输入数字,为必答项!</label></div>";
}else if(checkType == "DIGITS"){
errorHtml="<div class=\"errorItem\"><label for=\"\" class=\"error\">请输入整数,为必答项!</label></div>";
}else if(checkType == "TELENUM"){
errorHtml="<div class=\"errorItem\"><label for=\"\" class=\"error\">请输入电话,为必答项!</label></div>";
}else if(checkType == "PHONENUM"){
errorHtml="<div class=\"errorItem\"><label for=\"\" class=\"error\">请输入手机,为必答项!</label></div>";
}else if(checkType == "TELE_PHONE_NUM"){
errorHtml="<div class=\"errorItem\"><label for=\"\" class=\"error\">请输入电话或手机,为必答项!</label></div>";
}else if(checkType == "DATE"){
//2014-01-01 12:00:00
errorHtml="<div class=\"errorItem\"><label for=\"\" class=\"error\">请输入如2014-01-01为必答项</label></div>";
}else if(checkType == "IDENTCODE"){
errorHtml="<div class=\"errorItem\"><label for=\"\" class=\"error\">请输入身份证号,为必答项!</label></div>";
}else if(checkType == "ZIPCODE"){
errorHtml="<div class=\"errorItem\"><label for=\"\" class=\"error\">请输入邮编,为必答项!</label></div>";
}else if(checkType == "URL"){
errorHtml="<div class=\"errorItem\"><label for=\"\" class=\"error\">请输入URL为必答项</label></div>";
}
quItemBody.find(".quCoItem").append(errorHtml);
}
}
@ -397,7 +433,7 @@ $(document).ready(function(){
$(".fillblankInput,.dwMFillblankInput").blur(function(){
lgcommon($(this));
answerProgressbar($(this));
validateCheck($(this).parents(".li_surveyQuItemBody"),false);
validateCheck($(this).parents(".li_surveyQuItemBody"),true);
});

View File

@ -545,6 +545,7 @@ $(document).ready(function(){
$("#dwDialogQuFillOptionSave").click(function(){
var quItemBody=$(dwDialogObj).parents(".surveyQuItemBody");
var quFill_checkType=$("#modelUIDialog select[name='quFill_checkType']");
var qu_inputWidth=$("#modelUIDialog input[name='qu_inputWidth']");
var qu_inputRow=$("#modelUIDialog input[name='qu_inputRow']");
var option_range_date=$("#modelUIDialog select.option_range_date");
@ -554,12 +555,17 @@ $(document).ready(function(){
var answerInputRow=quItemBody.find("input[name='answerInputRow']");
var paramInt01=quItemBody.find("input[name='paramInt01']");
if(answerInputWidth.val()!=qu_inputWidth.val() || answerInputRow.val()!=qu_inputRow.val()){
if(answerInputWidth.val()!=qu_inputWidth.val() || answerInputRow.val()!=qu_inputRow.val() || (checkType[0] && checkType.val()!=quFill_checkType.val())){
quItemBody.find("input[name='saveTag']").val(0);
}
var checkTypeVal = quFill_checkType.val();
if(checkTypeVal == ""){
checkTypeVal="NO";
}
if(checkType[0]){
var checkTypeVal = checkType.val();
checkType.val(checkTypeVal);
if(checkTypeVal=="DATE"){
if(paramInt01[0]){
paramInt01.val(option_range_date.val());
@ -1397,6 +1403,7 @@ function showUIDialog(thDialogObj){
}
var qu_inputWidth=$("#modelUIDialog input[name='qu_inputWidth']");
var qu_inputRow=$("#modelUIDialog input[name='qu_inputRow']");
var quFill_checkType=$("#modelUIDialog select[name='quFill_checkType']");
if(answerInputWidth_val==""){
answerInputWidth_val="300";
}
@ -1405,6 +1412,7 @@ function showUIDialog(thDialogObj){
}
qu_inputWidth.val(answerInputWidth_val);
qu_inputRow.val(answerInputRow_val);
quFill_checkType.val(checkType_val);
$("#modelUIDialog .dwQuFillDataTypeOption .option_range_date_li").hide();
if(checkType_val==="DATE"){
@ -1415,7 +1423,7 @@ function showUIDialog(thDialogObj){
}
resetQuItemHover(quItemBody);
$(thDialogObj).parents(".quCoItemUlLi").addClass("menuBtnClick");
$("#modelUIDialog").dialog("option","height",220);
$("#modelUIDialog").dialog("option","height",260);
}else if(thObjClass.indexOf("quCoOptionEdit")>=0) {
$("#modelUIDialog .dwQuRadioCheckboxOption").show();
//设置回显值 isNote checkType