jquery-validate

jQuery validate - User must select YES radio (not no) in order to conitnue

泄露秘密 提交于 2019-12-22 06:47:34
问题 I would like to set up a jQuery validate rule to require that YES (not no) be checked in order for the form to validate/submit. User must accept terms. If the user selects no they will get the error msg and the form will not validate. What is the correct way to accomplish this using jquery validate plugin? <form id="myForm"> <input type="radio" name="terms" id="terms1" value="Yes!" class="required" title="Must accept terms to continue" /> Yes <input type="radio" name="terms" id="terms2" value

Prevent jquery-validate from using the title attribute as an error message?

大城市里の小女人 提交于 2019-12-22 06:36:24
问题 Jquery validate uses the title attribute as the error message. I use the title attribute to provide user tooltips, but I don't want it to replace validation error messages. In this complete example, I've set the Last Name field to have a title attribute while leaving the First Name field without a title attribute. When the form submits, the First Name field properly displays the error message - " This field is required. ", while the Last Name field displays the contents of the title attribute

How to fire an event on error in jquery validator plugin

孤街浪徒 提交于 2019-12-22 03:52:21
问题 I have jquery validator running and the page is very long, so I want the page to scroll up to the top because I display errors on the very top of the page above the form, does anyone know where I can put the code for the animation so it fires when the form has errors? 回答1: You can use the invalidHandler option for the exact case you want, like this: $("form").validate({ rules: { ... rules here ... } invalidHandler: function(form, validator) { $('html, body').animate({scrollTop: '0px'}, 300);

multiple jquery validators on one form

筅森魡賤 提交于 2019-12-22 01:11:42
问题 I'm using jquery.validate plugin and facing the following situation: <form id="myForm" ....> <input type="text" id="value1"/> <!-- Here is some code rendered from the partial --> <script type="text/javascript"> $(document).ready(function() { var validator = $('#myForm').validate({ rules: { value_from_partial: { required: true } }, messages: { value_from_partial: { required: "Enter your firstname" } }, submitHandler: function() { alert("submitted!"); } }); }); </script> <input type="text" id=

Make Jquery validation plugin work on inputs with no name attribute

大兔子大兔子 提交于 2019-12-21 12:35:38
问题 Well it took me long enough to find out that the JQuery form validation plugin only works on fields with a "name" attribute. Anyway, I use it to make all the fields required. My problem is that at some point, I have one text input <div id='choices'> <input type='text' /> </div> <a href='#' id='add-choice' >Add input </a> the user can add as many text inputs as he wants : $("#add-choice").live("click",function(){ $("#choices").append("<input type='text' /><br>"); }); And I want these new

Validate Form Twice

百般思念 提交于 2019-12-21 12:28:15
问题 Code facts: I am using jQuery Also using the jQuery Validate plugin Features of my form: I have a form that is split up into two parts. It's all one form but broken up by two large divs The meat of the form (first name, last name, etc) is on the first part. I also have a dynamic table on the first part of the form, so people can register themselves and up to 20 other people. Finally, there is a registration code. These codes are only usable up to 20 times. Meaning if one person registers

jQuery Validation - form.valid() always returning true

☆樱花仙子☆ 提交于 2019-12-21 11:59:07
问题 I have a situation when I try to check if a form is valid, but form.valid() always returns true. But if I try to validate the individual control, it returns false. This is my form: <div class="profilestagsedit"> @using (Html.BeginForm("", "", FormMethod.Post, new { id = "tagsform" })) { @Html.ValidationMessageFor(x => x.EditTagsText) @Html.TextBoxFor(p => p.EditTagsText, new { @id = "txtprofileedittags" }) } </div> This is my viewmodel: [Required(AllowEmptyStrings = false, ErrorMessage =

how can remove backslash in value by jQuery?

淺唱寂寞╮ 提交于 2019-12-21 08:26:08
问题 if $(this).val() have backslash remove backslash in it by jQuery. how is it? 1111\/11\/11 -> 1111/11/11 回答1: $(this).val().replace(/\\/g, ''); You have to use two backslashes to get the \ character. A single backslash is used for control characters such as \r \n etc. Using the double backslash escapes this and gives you what you want. 回答2: var str = $(this).val().replace('/',''); 回答3: Try this. $(this).val($(this).val().replace(/\\/gi, "")); 来源: https://stackoverflow.com/questions/6758734/how

jquery validation for more than min value

杀马特。学长 韩版系。学妹 提交于 2019-12-21 06:59:51
问题 I am using the jquery validation plugin for form validation. Using the min property works fine, but I want it to validate values strictly greater than that min value. rules: { price: { required: true, min: 13, number: true } } In my code I have min: 13 , but I don't want to allow 13, only values greater than 13, e.g. 13.10, 13.20, 14. How can I do this? Thanks in advance ! 回答1: Create your own custom method with $.validator.addMethod: $.validator.addMethod('minStrict', function (value, el,

jquery datepicker and custom validation

↘锁芯ラ 提交于 2019-12-21 05:31:47
问题 I need to add custom validation(I think) for validating input from an user. Here's my use case: I'm using the jquery ui datepicker for selecting dates, with localization like this: $.datepicker.setDefaults( $.datepicker.regional[ currentLocale ] ); I use the bassistance validation plugin, and using rules for date:true and such does not work with different formats(or if they do please tell me how!). So I've made my own date validation methods like this $.validator.addMethod("validDate",