JQuery validation plugin - only numbers, minimum and maximum length - space

I use jQuery validation ( PLUGIN URL ) for most of my form validation:

I have the 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 problems with using space.

  • min and max length will take a space as a character
  • If a number = truespace is used, it will return an error since the space is not a number

Is there a workaround? Please note that I want to continue to enter a space (for readability).

+5
source share
2 answers

beforeValidation , : Jquery Validator , ,

+4

:

:

<input id="phone" type="number" maxlength="10" size="2" max="99" style="width:36px;" required />

.., !

0

All Articles