Showing posts with label How to Validate in ASP.net using Javascript. Show all posts
Showing posts with label How to Validate in ASP.net using Javascript. Show all posts

Monday, March 14, 2011

validation using javascript



/*
function validate()
{
// for check that text box is fill or empty.
     if (document.getElementById("<%=txtName.ClientID%>").value=="")

     {
                alert("Name Feild can not be blank");
                document.getElementById("<%=txtName.ClientID %>").focus();
                return false;
     }
     if(document.getElementById("<%=txtEmail.ClientID %>").value=="")
     {
                alert("Email can not be blank");
               document.getElementById("<%=txtEmail.ClientID%>").focus();
               return false;
     }
// check that email address is valid or not.
    var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
    var emailid=document.getElementById("<%=txtEmail.ClientID%>").value;
   var matchArray = emailid.match(emailPat);
    if (matchArray == null)
       {
                  alert("Your email address seems incorrect. Please try again.");
                  document.getElementById("<%=txtEmail.ClientID%>").focus();
                  return false;
       }
     if(document.getElementById("<%=txtCourse.ClientID%>").value=="")
     {
                alert("Cousrse field can not be blank");
               document.getElementById("<%=txtCourse.ClientID%>").focus();
               return false;
     }

     return true;
 }
</script> */