Reputation: 723
im new in jQuery.. and now try to learn and create a form with jQuery validation. Then, somebody can show me how to validate IC value. I/C value will need 12 digit and only a number.
from code below:
IC: {
required: true,
minlength: 12
},
user will can input more than 12digits. i want user can input only 12digits and only a number. how can i do that .?
here a full code.
(function($,W,D){
var JQUERY4U = {};
JQUERY4U.UTIL =
{
setupFormValidation: function()
{
$("#register-form").validate({
rules: {
regPassword: {
required: true,
minlength: 4
},
Designation: "required",
IC: {
required: true,
},
},
messages: {
regPassword: {
required: "<br><font color='red'>Enter Your Password</font>",
minlength: "<br><font color='red'>Your password must be at least 4 characters long</font>"
},
IC: "<br><font color='red'>Enter Your I/C Number</font>",
},
submitHandler: function(form) {
form.submit();
}
});
}
}
//when the dom has loaded setup form validation rules
$(D).ready(function($) {
JQUERY4U.UTIL.setupFormValidation();
}); })(jQuery, window, document);
Upvotes: 0
Views: 1739
Reputation: 98748
Quote OP:
show me how to validate IC value... will need 12 digit and only a number.
Use required: true
, number: true
, and rangelength: [12, 12]
to require only a 12-digit number. See documentation for a list of all methods/rules.
rules: {
IC: {
required: true,
number: true,
rangelength: [12, 12]
}
},
Upvotes: 1