Jqeury Validate() special function
Posted
by kevin
on Stack Overflow
See other posts from Stack Overflow
or by kevin
Published on 2010-04-09T21:04:13Z
Indexed on
2010/04/16
19:43 UTC
Read the original article
Hit count: 382
Hi there, i'm using the Jquery validate() plugin for some forms and it goes great. The only thing is that i have an input field that requires a special validation process. Here is how it goes:
The Jquery validate plugin is called in the domready for all the required fields.
Here is an exemple for an input:
<li>
<label for="nome">Nome completo*</label>
<input name="nome" type="text" id="nome" class="required"/>
</li>
And here is how i call my special function:
<li>
<span id="sprytextfield1">
<label for="cpf">CPF* (xxxxxxxxxxx)</label>
<input name="cpf" type="text" id="cpf" maxlength="15" class="required" />
<span class="textfieldInvalidFormatMsg">CPF Inválido.</span>
</span>
</li>
And at the bottom of the file i call the Spry function:
<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1","cpf");
//-->
</script>
Of course i call the Spry css and js files in the head section as well as my special-validate.js.
When i just use the Jquery validate() plugin and click on the send button, the page goes automatically back to the first mistaken input field and shows the error type (not a number, not a valid email etc.).
But with this new function, this "going-back-to-the-first-mistake" feature doesnt work, of course, because the validate() function sees it all good.
I already added a rule for another form (about pictures upload) and it goes like this:
$("#commentForm").validate({
rules: {
foto34: {
required: true,
accept: "jpg|png|gif"
}
}
});
Now my question is, how can i add the special validation function as a rule of the whole validation process ?
Here is the page to understand it better: link text and the special field is the first one: CPF.
Hope i was clear explaining my problem. Thanks in advance. kevin
© Stack Overflow or respective owner