Ajax (1) Apex Class (12) Apex Trigger (2) Community (2) Home Page (1) HTML (4) Integration (3) JS (7) KB (1) Label (1) Licenses (1) Listing (1) Log (1) OOPs (5) Sharing (1) Static Resource (1) Test Class (3) URI (1) Visualforce (10)

Saturday, 20 June 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