1

The idea is to check only positive integer with no zero , however, the added custom rule do not work, how to fix it? Thank you.

    $(document).ready(function(){
  $("#genForm").validate( {
      rules: {
         'fb' : {
              number: true
          },
     'order[]' : {
               required: true,
              number : true
          }, 
           parent: {
      required: function(element) {
        return $("#order[]").val() < 0 ;
      }}       

       }
   });

   $("#order[]").blur(function() {
  $("#parent").valid();
});

html:

foreach ($result as $set) // it determine how many text input box in total
{
<input type='text' id="order[]" name="order[]" >
}

further explanation:

 <input type='text' id="order[]" name="order[]" value="-1" > //not allowed case 1

 <input type='text' id="order[]" name="order[]" value="5" > //not allowed case 2
 <input type='text' id="order[]" name="order[]" value="5" > //not allowed case 2
 <input type='text' id="order[]" name="order[]" value="2" > //not allowed case 2
5
  • 1
    Have you defined positiveinteger as a custom rule anywhere? Commented Apr 14, 2012 at 5:51
  • sorry, how to define it? i have a regex "(^\d*\.?\d*[1-9]+\d*$)|(^[1-9]+\d*\.\d*$)" for this actually Commented Apr 14, 2012 at 5:56
  • 1
    You need to define it. Also, a regex is a poor choice when you could use value > 0. Commented Apr 14, 2012 at 5:59
  • You can see an example of custom validation method in their docs. Return true if it passes validation, false if not. docs.jquery.com/Plugins/Validation/Methods/… Commented Apr 14, 2012 at 6:02
  • Thank you for yours suggestion, i have add the custom rule , but it does not work still, are there any thing i am still missing? Thanks Commented Apr 14, 2012 at 6:10

1 Answer 1

1

are you sure your syntax is correct here?

return order[] > 0;
Sign up to request clarification or add additional context in comments.

9 Comments

besides the >0 , can i check the element in order[] are not the same? for example, the {2,2,1,5} is not allowed , thank you
Sorry but I have tried return $("#order[]") > 0 ; and <input type='text' id="order[]" name="order[]">
i don't completely get what you are trying to do here. are you trying to loop through all the elements in the order ARRAY, or is order a single element? Can you just explain all that you want to do, that might help.
Sorry for confusing you. order[] is serveal text inputbox named order[] ,they should not <0 or have the same value of other inputbox. I have updated the question too, hope it can explain it. Please feel free to ask question if you have some part unclear.
Thanks your help, i have further explain it in real html case
|

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.