$.validator.addMethod not recognized
Hi,
I am developping a webApp in Groovy Grails Tools Suite and i am trying to use the jQuery validation plugin to validate a field in my HTML.
the problem is that even if i added the library in my project, the validator.addMethod is not recognized.
Here is the part that don't work in my .js code:
- $( document ).ready(function() {
- $.validator.addMethod("regex",function(value, element, regexp) {
- var re = new RegExp(regexp);
- return this.optional(element) || re.test(value);
- }, "Format invalide"
- );
-
- $("form[name='EditionForm']").validate({
- // Specify validation rules
- rules: {
- // The key name on the left side is the name attribute
- // of an input field. Validation rules are defined
- // on the right side
- ReferenceMetier:{
- required:true,
- regex:/^[0-9]{11}[A-Z]{1}$/,
- },
- },
- // Specify validation error messages
- messages: {
- ReferenceMetier:{
- required:"Please enter your ReferenceMetier",
- }
- },
- // Make sure the form is submitted to the destination defined
- // in the "action" attribute of the form when valid
- submitHandler: function(form) {
- form.submit();
- }
- });
- });
and here is the part of my .html code that uses the .js :
- <form method="post" name="EditionForm" id="EditionForm" >
- <div class="Separateur">
- <b><h2>Saisie Separateur</h2></b>
- <label id="date_recep" for="DatePicker">Date de reception</label> : <input type="text" class="DatePicker" name="DatePicker" id="DatePicker" size="30" maxlength="30"/>
- <label id="dest" for="Destinataire">Destinataire</label> : <input type="text" name="Destinataie" id="Destinataire" placeholder="" size="30" maxlength="30"/>
- <label id="grpdest" for="GroupeDestinataire">Groupe Destinataire</label> : <input type="text" name="GroupeDestinataie" id="GroupeDestinataire" placeholder="" size="30" maxlength="30"/>
- <label id="refmetier" for="ReferenceMetier">Reference Metier</label> : <input type="text" name="ReferenceMetier" id="ReferenceMetier" placeholder="" size="30" maxlength="30" required/>
- </br>
- </br>
- </div>
- </form>
and now the chrome error message:
editionintercalaire.js:53 Uncaught TypeError: Cannot read property 'addMethod' of undefined
at HTMLDocument.<anonymous> (editionintercalaire.js:53)
at l (jquery-1.8.3.min.js:2)
at Object.fireWith [as resolveWith] (jquery-1.8.3.min.js:2)
at Function.ready (jquery-1.8.3.min.js:2)
at HTMLDocument.A (jquery-1.8.3.min.js:2)
ask if i forgot something, thx for helping anyway.