eddy
eddy

Reputation: 4413

Using jquery Dialog with the Validation plugin

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??

Upvotes: 1

Views: 734

Answers (1)

Matt Ball
Matt Ball

Reputation: 359776

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+)?$/

Upvotes: 2

Related Questions