jQuery Validation [Number]

Here is simple jQuery validation.

HTML code:

<form id=”formId” method=”post”>
<div class=”body”>
<input class=”form-control text-right” type=”number” name=”fieldName” min=”0″ max=”1000″ />
</div>
<div class=”footer”>
&…


This content originally appeared on DEV Community and was authored by bikashgosai

Here is simple jQuery validation.

HTML code:

<form id="formId" method="post">
<div class="body">
<input class="form-control text-right" type="number" name="fieldName" min="0" max="1000" />
</div>
<div class="footer">
<button type="button" onclick="clearValidation()" class="btn btn-sm" >Cancel</button>
<button id="btnSubmit" type="button or submit" class="btn btn-sm">Submit</button>
</div>
</form>

Put this code on document ready.

$("#formId").validate({
        rules: {
            fieldName: {
                required: true,
                number: true,
                min: 1
            }
        },
        messages: {
            fieldName: {
//Custom messages
                required: "Required",
                min: "Value must be greater than 0"
            }
        }
    });

Check if fields are valid according to rules defined above:

var form = $("#formId");
    if (form.valid()) {
        //do something...
    }
else
{
return;
}

This is code for removing validation on form.


function clearValidation() {
    var form = $("#formId").validate();
    form.resetForm();
}


This content originally appeared on DEV Community and was authored by bikashgosai


Print Share Comment Cite Upload Translate Updates
APA

bikashgosai | Sciencx (2021-12-23T11:18:38+00:00) jQuery Validation [Number]. Retrieved from https://www.scien.cx/2021/12/23/jquery-validation-number/

MLA
" » jQuery Validation [Number]." bikashgosai | Sciencx - Thursday December 23, 2021, https://www.scien.cx/2021/12/23/jquery-validation-number/
HARVARD
bikashgosai | Sciencx Thursday December 23, 2021 » jQuery Validation [Number]., viewed ,<https://www.scien.cx/2021/12/23/jquery-validation-number/>
VANCOUVER
bikashgosai | Sciencx - » jQuery Validation [Number]. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/23/jquery-validation-number/
CHICAGO
" » jQuery Validation [Number]." bikashgosai | Sciencx - Accessed . https://www.scien.cx/2021/12/23/jquery-validation-number/
IEEE
" » jQuery Validation [Number]." bikashgosai | Sciencx [Online]. Available: https://www.scien.cx/2021/12/23/jquery-validation-number/. [Accessed: ]
rf:citation
» jQuery Validation [Number] | bikashgosai | Sciencx | https://www.scien.cx/2021/12/23/jquery-validation-number/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.