You need to sign in to do that
Don't have an account?

How to validate the phoen number in custom vfpage
Hi all,
Canyone help me how to validate the phone number in custom vfpage bfeore redirecting to next page. I'm tried with the standard validation but it fires after submitting the record.
Thanks in advance.
Regards,
mac.
Canyone help me how to validate the phone number in custom vfpage bfeore redirecting to next page. I'm tried with the standard validation but it fires after submitting the record.
Thanks in advance.
Regards,
mac.
Hi Mac,
Please use Jquery or javascript validation method, this will validate the phone field on VF page itself.
Thanks,
Gaurav
SKype: gaurav62990
Can you explain how to use java script in hte vfpage.
Please check this blog for understanding basic concept of Jquery validation in custom pages.
https://www.sitepoint.com/basic-jquery-form-validation-tutorial/
Hope this helps !!!
Thanks,
Gaurav
vf page code
<apex:inputText value="{!SearchNumber}" id="txt1" styleClass="input-element" onchange="validatenumber()"/>
<script type="text/javascript"> function validatenumber(){ var inputtxt = document.getElementById('p:ff:txt1'); var phoneno = /^(1\s|1|)?((\(\d{3}\))|\d{3})(\-|\s)?(\d{3})(\-|\s)?(\d{4})$/; var phoneno1 = /^(1\s|1|)?((\(\d{3}\))|\d{3})(\.|\s)?(\d{3})(\.|\s)?(\d{4})$/; if(inputtxt.value.match(phoneno) || inputtxt.value.match(phoneno1)){ return true; } else { alert('Enter Valid number'); inputtxt.value = ''; return false; } } </script>
Thanks for the replay. I want to show the error message than showing an alert. Is it possible to show the error message than a alert ,,,?
I am not sure that show the error message first then alert. I thing it is possible through Java script or jquery .
I thing you try java script to show the msg then alert
Thanks
Vikas Rathi
VF PAGE:
<apex:page id="pg" controller="opportunityvalidateclass" >
<apex:form id="fm">
<script >
function show()
{
var phn=document.getElementById("{!$Component.pg.fm.pgb.pbs.one}");
var pattern=/^\d{10}$/;
if(!pattern.test(phn.value))
{
alert("Mobile should be 10 digits");
phn.focus();
return false;
}
}
</script>
<apex:pageBlock id="pgb" title="Opportunity validation">
<apex:pageBlockSection columns="1" id="pbs">
<apex:inputText label="Opportunity Name" value="{!Name}" />
<apex:inputText label="Opportunity phone" value="{!phone}" id="one" />
<apex:inputText label="Opportunity Pincode" value="{!pincode}" />
</apex:pageBlockSection>
<apex:pageBlockButtons location="Bottom">
<apex:commandButton value="validate" onclick="show()" />
<apex:commandButton value="save" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class opportunityvalidateclass {
public string Name{set;get;}
public string phone{set;get;}
public string pincode{set;get;}
public string email{set;get;}
public void insertit(){
Opportunity o=new Opportunity();
o.Name=Name;
o.shobithapp__TrackingNumber__c=phone;
insert o;
}
}
hope this helps you..
Thanks
Vishnu R