Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Age and Email validation by using javasciprt

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 124
    Comment on it

    Lets see an illustration how we can validate age and email id through javascript

    alt text alt text

    In this example,we are taking inputs from user in age(textbox) and Email (Textbox). By using functions of javascript we can validate both the values.

     function ValidateAge()
        {
         //age numeric validation 
        if(document.getElementById("txtempage").value=="")
        {
         alert("Enter the age")
         document.getElementById("txtempage").focus();
         return false;
         } 
         var digits=RegExp(/^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/); 
         var digitsid=document.getElementById("txtempage").value;
         var digitsArray = digitsid.match(digits);
         var temp;
         if (digitsArray == null)
        {
                   alert("Your age is incorrect");
                   document.getElementById("txtempage").focus();
                   return false;
        }
    
        //Email Validation
         if(document.getElementById("txtemail").value=="")
          {
                     alert("Email id can not be blank");
                    document.getElementById("txtemail").focus();
                    return false;
          }
         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").value;
         var matchArray = emailid.match(emailPat);
         if (matchArray == null)
        {
                   alert("Your email address seems incorrect. Please try again.");
                   document.getElementById("txtemail").focus();
                   return false;
        }
    
        }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: