1

For years I was jQuery.validate using version 1.9.0 successfully
Now, with v 1.19.2 I get "jquery.format is not a function".
In my head section:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.2/jquery.validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.2/additional-methods.min.js" ></script>    

html form input

<div class="divTableCell L3"><input name="email" type="text" class="required" id="email" /></div>

At bottom:

<script>
    formVerif();
</script>

This is a part of the function used:

function formVerif(){   
    $(document).ready(function(){
        $("#formulario").validate({
          errorClass: 'rojo' ,
          messages: {
               nombre: {
                 required: "<br />Falta ingresar un nombre.",
                 minlength: jQuery.format("<br />Ingresa al menos {0} caracteres"),
                 maxlength: jQuery.format("<br />Ingresa como máximo {0} caracteres"),
                 alphanumeric: "<br />Ingresa solo letras y espacios"
                 },
               apellido: {
               ...
               ...

If I go back to V 1.9.0 no errors are displayed:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="JS/jquery.validate.min.js"></script>
<script src="JS/additional-methods.min.js"></script>
1
  • There is no such thing as jQuery.format - it should be jQuery.validator.format. Your example code is also incomplete. You only show us the HTML for the field with name="email" and then show the .validate() method with completely different fields. Commented Jan 11, 2021 at 18:54

2 Answers 2

3

Your code...

minlength: jQuery.format("<br />Ingresa al menos {0} caracteres"),

There is no such thing as jQuery.format, so just remove and use this...

minlength: "<br />Ingresa al menos {0} caracteres",

It still works the same...

DEMO: jsfiddle.net/w09fqj3n/

Reviewing the documentation, jQuery.format is supposed to be jQuery.validator.format, but it's apparently optional.


Also, putting the DOM ready event handler inside a function that you call at the bottom of the page does not make sense...

function formVerif(){   
    $(document).ready(function(){ ....

The main purpose of the ready event handler is to "Specify a function to execute when the DOM is fully loaded." Calling it from a function at the bottom of the page renders its usage completely pointless. Just put the ready handler at the bottom if you wish to defer loading scripts until the end.

Sign up to request clarification or add additional context in comments.

Comments

0
 jQuery.validator.addMethod("extension", function(value, element, param) {
                            param = typeof param === "string" ? param.replace(/,/g, '|') : "png|jpe?g|gif";
                            return this.optional(element) || value.match(new RegExp(".(" + param + ")$", "i"));
                        },  jQuery.format("Please enter a value with a valid extension."));

remove jQuery.format()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.