Thursday, September 25, 2014

JQuery Validations

Code Snippet for validating the textbox, dropdownlist, and radiobuttonlist in ASP.NET page using Jquery.

To check Textbox value:

txtName is the textbox id:

if ($.trim($("#txtName").val()).length == 0) {
//Enter a name
}

To check Whether entered value is number or not:

$.isNumeric(value) method can be used to check for number

var age = $.trim($("#txtAge").val());
if ($.isNumeric(age)) {
//Entered number is Numeric
}

To check whether any radio button is checked:

rdbGender is the Radiobuttonlist id:

if ($("#rdbGender input:checked").length == 0) {
//Gender is not selected
}

To check whether any dropdownlist value is checked:

ddlQualification is the Dropdownlist id:

if ($("#ddlQualification option:selected").val() == 0) {
//Qualification is not selected
}


Total Source Code



Output Screen