嗨,我正在使用
jquery验证插件.
我有一个奇怪的问题,我有一个这样的有效性
- jQuery("#profile_info").validate({
- rules : {
- city : {
- required : true,minlength : 3,maxlength : 30,cityvalidation: true
- },state : {
- required : true,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",}
- }
- });
和城市验证
- 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>
如果城市验证失败. “你已经键入不允许的Charactors”消息,而不是显示字段的标题.
>如果我删除标题,它的工作完美.所以我假装做了我想得到自定义的错误信息而不是标题.请帮忙……..
提前致谢 …………………
解决方法
嗯我发现了.
我用了ignoreTitle:true,
- jQuery("#profile_info").validate({
- ignoreTitle: true,rules : {
- city : {
- required : true,}
- }
- });