Thursday, 12 June 2014

Useing JavaScript Email validation



function name_function()
{
                var          pattern=/^([a-zA-Z\ \']+)$/;
                var name=document.getElementById("Textbox_name");
               
                if(name.value=="")             // Empty Data Validation
                {
                                alert("You cannot leave the Name Field Empty ");
                                return false;
                }
                else if(!pattern.test(name.value))                                                                                                           // Invalid Format of Name Validation
                {
                                alert("Invalid Format of Name");
                                document.getElementById("applicant_name").focus();
                                return false;
                }
}

function email_function()
{
                var regexpemail=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                var email_id=document.getElementById("Textbox_name_email_id");
               
                if(email_id.value=="")
                {
                                alert("You can't Leave the Email ID Field Empty ");
                                return false;
                }
                else if(!regexpemail.test(email_id.value))
                {
                                alert("Invalid Format of Email ID");
                                document.getElementById("email_id").focus();
                                return false;
                }
}

function mobile_function()
{
                var regexpmobile=/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
                var mobile=document.getElementById("Textbox_name_mobile_no");
               
                if(mobile.value=="")
                {
                                alert("You cannot leave The mobile Number Field Empty ");
                                return false;
                }
                else if(!regexpmobile.test(mobile.value))
                {
                                alert("Invalid Format of Mobile number");
                                document.getElementById("mobile_no").focus();
                                return false;
                }
}

No comments:

Post a Comment