Saturday, June 20, 2015

Email and Phone Validation


<apex:page id="page" >
    <apex:form id="form">
        <apex:outputPanel id="panel">
            <script>
                function isValidEmail() {
                   var obj = document.getElementById('{!$Component.email}').value;
                    var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;  
if(obj.match(mailformat))  
{   
return true;  
}  
else  
{  
alert("You have entered an invalid email address!Use format: a@b.cd or a@b.cde");   
return false;  
                }
            </script>
            Email<br/>
            <apex:inputText id="email"  onblur="isValidEmail();" />
        </apex:outputPanel>
<apex:outputPanel id="panel2">
            <script>
                function isValidPhone() {
                   var objPhone= document.getElementById('{!$Component.phone}').value;
                   
  var phoneno3= /^\+?([0-9]{2})\)?[-. ]?([0-9]{10})$/;  
  var phoneno4= /^\+?([0-9]{3})\)?[-. ]?([0-9]{10})$/;   
  if(objPhone.match(phoneno3)||objPhone.match(phoneno4)) 
  {  
      return true;  
  }  
  else  
  {  
     alert("Not a valid Phone Number :User format +91-9015574663 or +912-9015574663");  
     return false;  
  }  
  }  
            </script>
           <br/> Mobile Phone<br/>
            <apex:inputText id="phone" onblur="isValidPhone();" />
        </apex:outputPanel>        
        
    </apex:form>
</apex:page>

No comments:

Post a Comment

Thanks for your comment