开发者

Jquery validation with zip codes

I have a program that allows a user to enter a zip code to generate a google map. I want to make sure that the zip code is 开发者_运维知识库valid. To do so I am using the jquery validate method. Here is how my code looks:

$('#zipInput').validator({
    format: 'zipUS',
    invalidEmpty: true,
    correct: function () {
       //Code for correct
    },
    error: function() {
      //Error code here
    }
});

The problem is that this is not working for me. I get the error $('#zipInput').validator if not a function. I have been looking for examples of the validate method online and I used this link to build my code. I have added jquery.validate.js to my web page as well (issue with incorrect sources maybe?) Any suggestions or examples that I could look at to help figure out my issue?

EDIT: Here is all of the scripts I use in order:

<script src="jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="jquery-ui-1.8.11.custom.min.js" type="text/javascript"></script>
<script type="text/javascript" src="jquery.jscrollpane.min.js"></script>
<script src="mwheelIntent.js" type="text/javascript"></script>
<script src="jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="Default.js" type="text/javascript"></script>


You need to do at least two things:

  1. Load jQuery itself before the plugin.
  2. Enclose your code in a jQuery.ready() construct.

If you are already doing so, please post all the relevant code.


You have to put a call to the validator code you've written inside the function which you are using to call the dialog. This is if the validator code is in the dialog which you are loading.

Another idea is to put the validator code inside the jquery.ready function in the form from which you load the dialog, but this will add some redundant code to that page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜