Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery validation plugin - numbers only, min & max length - space issue

I'm using jQuery Validation (PLUGIN URL) plugin for most of my form validation:

I have following example (LIVE EXAMPLE):

FORM:

 <form class="form" id="feedback-form" method="post" action="#">


    <label for="phone">Contact number:</label>
    <input type="text" value="" id="phone" name="phone" class="required">
    <br class="clr">

    <div class="form-buttons">
        <input id="submit" type="submit" value="Submit" class="button" >
    </div>
    <br class="clr">
    <br /><br />

</form>

jQuery:

$("#feedback-form").validate({
    rules: {

        phone: {
            number: true, // as space is not a number it will return an error
            minlength: 6, // will count space 
            maxlength: 9
        }

    }

});

I have two issues, both relating to space usage.

  • min & max length will count space as an character
  • if number = true and space is used, it will return error as space is not a number

Is there any workaround this? Have any of you bumped in on the same problem? Please note I want to keep allowing to type in space (for readability).

like image 496
Iladarsda Avatar asked Oct 11 '22 02:10

Iladarsda


1 Answers

You can add a beforeValidation callback to send the value without spaces, take a look here: Jquery Validator before Validation callback, it seems to be what you're looking for

like image 150
Soufiane Hassou Avatar answered Oct 18 '22 03:10

Soufiane Hassou