0

Here is my my form input: I will have multiple, i want to validate all dynamically!

  <input type="number" name="bill[1][amount]" class="form-control" placeholder="Enter bill amount">

And here is my jquery code:

$("#bulkForm").validate({
            rules:
                 {
                  "bill[][amount]":
                          {
                             number: true,
                             required: true
                          }
                 },

                 submitHandler: function(form) {

                    var params = $("#bulkForm").serialize();

 });
3
  • Hi @Wiki Babu, pls upload your full form, i will solve it Commented Dec 7, 2019 at 15:24
  • Please read minimal reproducible example to complete your question, what you tried, and what you are blocked on, the error or issue you encounter, ... Commented Dec 7, 2019 at 15:25
  • jsfiddle.net/Yy2gB/10 Commented Dec 7, 2019 at 15:27

1 Answer 1

1

Here is solution, if you've dynamic input and validate each input

$(function(){
	$("#bulkForm").validate();
        $("[name^=bill]").each(function(){
    	$(this).rules("add", {
         	required: true,
       		number: true,
       		messages: {
            	required: "Please enter number"
       			}
     		});   
   		});
   		})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
	<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.validate.js"></script>
  <form action="" id="bulkForm" >
		  <input type="text" name="bill[1][amount]" class="form-control" placeholder="Enter bill amount">
		  <br><input type="text" name="bill[2][amount]" class="form-control" placeholder="Enter bill amount">
		  <br>
	<input type="submit" name="submit" value="Submit">
	</form>
	

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you but i'm wondering where can i submit the form. Please add submitHandler code as well!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.