Validation: valid() doesn't always seem to work?

Validation: valid() doesn't always seem to work?

Hi all,
I'm working on a larger project, but to demonstrate my issue, I created a small test page. I tried using a addMethod() for GPS coordinates and also a simple addClassRules() with range, and neither seem to be doing the job correctly. What am I missing?

In essence, the name field is required, Latitude needs to be between -90/90 and Longitude between -180/180, but Latitude/Longitude is not required. When I click the Validate button, even if the Latitude or Longitude values are out of range, valid() returns true so long as the Name field has anything in it. You can add a name field, enter invalid parameters to Latitude/Longitude and see it complain about the values, but the $('#myForm').valid() still returns true when there are invalid parameters.

  1. <html>
    <head>
    <script type="text/javascript" src="./jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="./jquery.validate.js"></script>
    </head>
    <body>
    <form id="myForm">
    <p>Name: <input type="text" id="name" class="required" style="width:100px;"/></p>
    <p>Latitude: <input type="text" id="latitude" class="gps-latitude" style="width:100px;"/></p>
    <p>Longitude: <input type="text" id="longitude" class="gps-longitude" style="width:100px;"/></p>
    <input type="button" value="Validate" onclick="javascript:void(isFormValid())"/>
    </form>
    </body>

    <script type="text/javascript">
            $().ready(function () {
        $('#myForm').validate();
        });

    /*     $.validator.addMethod("gps-latitude", function(value, element) {
            return this.optional(element) || (value >= -90 && value <= 90)
        }, "<br/>Please enter a value between -90 and 90");

        $.validator.addMethod("gps-longitude", function(value, element) {
            return this.optional(element) || (value >= -180 && value <= 180)
        }, "<br/>Please enter a value between -180 and 180");*/







        $.validator.addClassRules("gps-latitude", { range: [-90, 90] });
        $.validator.addClassRules("gps-longitude", { range: [-180, 180] });


        function isFormValid() {
            $('#myForm').validate();
            if (!$('#myForm').valid()) {
                alert("Form has errors");
                return false;
            }
            return true;
        }
    </script>
    </html>