Wednesday, 1 August 2012

Required field validation using jquery:


Jquery is same and as it is javascript library that which same as the functions as predefined which is gone acess by adding jquery file which make you to acess some functions like test,value like that as sample example shown below that having the function that which I wrote in last post in javascript  do same with jquery is easy… as the same functionality with jquery as follows:

$(document).ready(function () {
               $("#state").change(function () {
                   var selstate = $("#state option:selected").val();
                   $("#textmargin7").val(selstate);
               });

               $("#submitbtn").click(function () {

                   if ($("#title").val() == "") {
                       $('#titleError').html("Name is Required");
                      
                   }
                   else {
                       $('#titleError').html("*");
                       
                   }

                   if ($("#title1").val() == '') {
                       $('#titleError1').html("Email is Required");
                      
                   }
                   else {
                      
                       var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
                       if (!emailReg.test($("#title1").val())) {
                           alert("Email is Not Valid");
                       }
                   }
                
                });
  
           });

As I did that in jquery the functions will be written in  
 $(document).ready(function () { “CODE GOES HERE”});


That as I did the above for required fields and email validation image below and third function is for email validation.. which gives alert window if we give mistake email account.. 





No comments:

Post a Comment