We want to validate the phone field that it should have 10 digits only and the last name should have text only so how to use the extension.
I hope below code should help you…..
Visualforce Page:
<apex:page standardController="Contact" sidebar="false" docType="html-5.0"> <apex:form > <apex:pageBlock title="Edit Contact"> <apex:pageBlockSection columns="1"> <apex:inputField value="{!Contact.FirstName}"/> <apex:inputField id="lastname" value="{!Contact.LastName}" onchange="allLetter();" /> <div id="err2" style="margin-left: 450px;margin-top: -28px;" ></div> <script type="text/javascript"> function allLetter() { var letters = /^[A-Za-z]+$/; var inputtxt=document.getElementById("j_id0:j_id1:j_id2:j_id3:lastname").value; if(!inputtxt.match(letters)) { document.getElementById("err2").innerHTML="Last Name must be text only"; }else{ document.getElementById("err2").innerHTML="Valid Name"; } } </script> <apex:inputField value="{!Contact.Email}"/> <apex:inputField value="{!Contact.Birthdate}"/> <apex:inputField id="phone" value="{!Contact.Phone}" onchange="checkPhone();" /> <div id="err1"></div> <script type="text/javascript"> function checkPhone(){ var phone=document.getElementById("j_id0:j_id1:j_id2:j_id3:phone").value; var letters = /^[A-Za-z]+$/; if(phone.length!=10 || phone.match(letters)) document.getElementById("err1").innerHTML="Phone must be 10 digits long. OR Can not contain Letters."; else document.getElementById("err1").innerHTML="Valid Phone Number"; } </script> </apex:pageBlockSection> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Save"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page> Result:-
We are the ISV Partners and Please reach us for custom development => www.merfantz.com
---------------------- We Are Happy To Helping You -----------------