gpt4 book ai didi

jquery验证,当输入字段具有标题属性时,给出错误消息标题而不是错误消息

转载 作者:行者123 更新时间:2023-12-03 22:07:49 25 4
gpt4 key购买 nike

嗨,我正在使用 jquery 验证插件。

我有一个奇怪的问题,我有一个这样的验证

jQuery("#profile_info").validate({

rules : {
city : {
required : true,
minlength : 3,
maxlength : 30,
cityvalidation: true
},
state : {
required : true,
minlength : 3,
maxlength : 30,
cityvalidation: true
}
},
messages : {
city : {
required : " City must be filled in",
minlength : "At least 3 characters long",
maxlength : "Should not exceed 30 characters",
},
state : {
required : " State must be filled in",
minlength : "At least 3 characters long",
maxlength : "Should not exceed 30 characters",
}
}
});

城市验证

jQuery.validator.addMethod("cityvalidation", function(value, element) {
return this.optional(element) || /^[a-zA-Z\u0080-\u024F\s\/\-\)\(\`\.\"\']+$/i.test(jQuery.trim(value));
}, "You Have Typed Unallowed Charactors");

我的输入字段是

                                                    <div class="select-date-container-side location-codes">
<input id="city" name="city"
value="<?php if(isset($profileinfo['CityName'])){echo $profileinfo['CityName'];}else if(isset($city)){echo $city;} ?>"
title="City" type="text"
class="smaler-textfield textfield clear-default"
tabindex="1900" />
</div>
<div class="select-date-container-middle location-codes">
<input id="state" name="state"
value="<?php if(isset($profileinfo['StateName'])){echo $profileinfo['StateName'];}else if(isset($state)){echo $state;} ?>"
title="State" type="text"
class="smaler-textfield textfield clear-default"
tabindex="1900" />
</div>

如果城市验证失败。 “您输入了不允许的字符” 消息,但显示的是字段标题。

enter image description here

  • 如果我删除标题,它就可以正常工作。所以我应该做什么。我想获取自定义错误消息而不是标题。请帮忙......

提前致谢......................

最佳答案

嗯,我找到了。

我使用了ignoreTitle:true,

jQuery("#profile_info").validate({


ignoreTitle: true,

rules : {
city : {
required : true,
minlength : 3,
maxlength : 30,
cityvalidation: true
},
state : {
required : true,
minlength : 3,
maxlength : 30,
cityvalidation: true
}
},
messages : {
city : {
required : " City must be filled in",
minlength : "At least 3 characters long",
maxlength : "Should not exceed 30 characters",
},
state : {
required : " State must be filled in",
minlength : "At least 3 characters long",
maxlength : "Should not exceed 30 characters",
}
}
});

关于jquery验证,当输入字段具有标题属性时,给出错误消息标题而不是错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10292602/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com