Monday, May 31, 2010

Function To Validate Mobile No. in JavaScript

function validateMobileNumber(idMobileNumber, idColumnLabelToHighlight)
{
    var varMobileNumber = document.getElementById(idMobileNumber).value;
    if(isNaN(varMobileNumber) || varMobileNumber.indexOf(" ")!=-1)
    {
        alert("Mobile Number : Enter numeric value");
        document.getElementById(idColumnLabelToHighlight).style.color="#ff0000";       
        return false; 
    }
    if (varMobileNumber.length != 10 )
    {
        alert("Mobile Number : Enter 10 characters valid mobile number without 0");
        document.getElementById(idColumnLabelToHighlight).style.color="#ff0000";       
        return false;
    }
   
    if (varMobileNumber.charAt(0)!=8 && varMobileNumber.charAt(0)!=9)
    {
     
        alert("Mobile Number : The number can only start with 8 or 9.");
        document.getElementById(idColumnLabelToHighlight).style.color="#ff0000";       
        return false
    }
   
    document.getElementById(idColumnLabelToHighlight).style.color="#000000";
    return true;
}

No comments:

Post a Comment