views:

141

answers:

0

I'm using jquery to validate an asp.net form (content within a master page). The required fields validation all works great, but I have a field that is not required, but if it does have text then it needs to be in the proper format. Jquery validates incorrect text just fine, but when the text is empty it stops the form from submitting (no error message though). Anyone have an idea why this could be happening or what to do about it?

 // Add validation rule for email
            if ($("input[id$='TextBoxEmail']").length) {
                $("input[id$='TextBoxEmail']").rules('add', {
                    required: false,
                    email: true,
                    messages: {
                        email: 'Please enter a valid email.'
                    }
                }); 
            }