Note : This post is first published on Sep-2014 in my previous blog Techkindle. Moving the content here.

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

To check Textbox value:

txtName is the textbox id:

[sourcecode language="javascript"] if ($.trim($(“#txtName”).val()).length == 0) { //Enter a name } [/sourcecode]

To check Whether entered value is number or not:

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

[sourcecode language="javascript"] var age = $.trim($(“#txtAge”).val()); if ($.isNumeric(age)) { //Entered number is Numeric } [/sourcecode]

To check whether any radio button is checked:

rdbGender is the Radiobuttonlist id:

[sourcecode language="javascript"] if ($(“#rdbGender input:checked”).length == 0) { //Gender is not selected } [/sourcecode]

To check whether any dropdownlist value is checked:

ddlQualification is the Dropdownlist id:

[sourcecode language="javascript"] if ($(“#ddlQualification option:selected”).val() == 0) { //Qualification is not selected } [/sourcecode]

Full Source Code

https://gist.github.com/gopigujjula/86ec2e3743d298b8caba

Output Screen

Happy Learning :)