1

Is it possible to use the validation plugin in a dialog like this? I have a page with 2 parts , Master and detail, in the first one I'm already using validation and is in the second one, the detail part, which is very similar to the example I mentioned above , where I'd like to use the validation plugin, but if it is not possible, would you mind telling me how I can allow only positive numbers (integers and decimals) ?

***EDITED

I've just found this regular expression: /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:.\d+)?$/ ,but it allows positive and negatives.What changes do I have to make to allow only positive numbers??

6
  • You do not need a regex to validate numbers. Commented Dec 16, 2010 at 14:00
  • @Matt. I know that, but I'm trying to use the checkRegexp function , that's why I need the regular expression. Commented Dec 16, 2010 at 16:47
  • @eddy: I edited my answer w/r/t the regex. I'm still not sure why you're using checkRegexp() to validate a number though. You can just combine number() and min(). Commented Dec 16, 2010 at 16:51
  • @Matt:Of course I can use those functions. Actually, I'm already using them in my Master form, but it's just that I have no idea how to validate more than one form, specially if one of them is a dialog Commented Dec 16, 2010 at 17:11
  • @Matt:I'll be very thankful ,if you could give me some guidance on how to do it Commented Dec 16, 2010 at 17:18

1 Answer 1

2

Of course it is possible. You just need to programmatically trigger form validation when the dialog is closed, and prevent it from being closed if validation fails:

var valid = $("#myform").validate().form();
if (valid)
{
    // allow the dialog to be closed
}
else
{
    // keep the dialog open
}

http://docs.jquery.com/Plugins/Validation/Validator/form

In fact, the demo you linked uses (custom) validation. Have a look at the JS source - actual validation logic aside, it's not too different from what your code will do.


You should just need to remove the first -? to make that regex allow only positive numbers:

/^(?:\d+|\d{1,3}(?:,\d{3})+)(?:.\d+)?$/
Sign up to request clarification or add additional context in comments.

2 Comments

Ok, but is it possible to do this: $("#MaterForm").validate() ; $("#DialogForm").validate() ; ?? I'm not sure :(
@eddy: what do you mean, "is it possible"? Sure, you can validate multiple forms programmatically - but that's not what that code does. What exactly are you trying to do? What hasn't worked, and in what way?

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.