add validation in jquery

How to add validation rules
in ready function

$.validator.addMethod(“myValue”, function (value, element, params) {

var isInvalidNumber = false;
var number = $(“#MyTextbox”).val()

if (number == “”) {
}
else {
number = parseFloat(number);
if (isNaN(number)) {
number = 0;
}

if (number > 100) {
isInvalidNumber = true;
}
}

return !isInvalidNumber;
}, $.format(“{1}”));
add rule in validation function

function validationRule() {
generateValidator($(“#myForm”));

//added validation code
$(“#mytextbox”).rules(‘add’, { checkValue: [“#mytextbox”, “no must not be fractional no.”] });

}

to show error popup use

<div id=”dummyDiv” style=”display: none”>
@Html.ValidationMessageFor(t => t.Name)
</div>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s