Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
NOT(REGEX(Phone, "\\D*?(\\d\\D*?){10}"))
<apex:inputfield value="{!yourbindedfield}" onblur="formatPhone(this);" />
Try below it validates that the number is in (999) 999-9999 format.
https://help.salesforce.com/articleView?id=fields_useful_validation_formulas_contact.htm&type=5
Thanks,
You can use formatPhone function of salesforce in inputfield or inputtext
How this function works, is written in below article.
https://help.salesforce.com/articleView?id=000330422&type=1&mode=1 (https://help.salesforce.com/articleView?id=000330422&type=1&mode=1)
Hope this helps!
Here is the Example to validate the phone number in this +XX (XXX) XXX-XXXX format. If you are using the phone field of any salesforce object then you can use this.
public boolean validatePhone(account acc){
if (acc.Phone != null){
String phoneNumber = acc.Phone ;
Pattern phonePattern = Pattern.compile('\\D*?(\\d\\D*?){10}');
Pattern numericPattern = Pattern.compile('[0-9]{10}');
Matcher phoneMatcher = phonePattern.matcher(phoneNumber);
if(phoneNumber.length() == 10) {
Matcher numericMatcher = numericPattern.matcher(phoneNumber);
if(numericMatcher.matches()) {
return true;
}else {
return false;
}
}else{
return false ;
}
}
}
Hope this explanation will resolve your query. Mark it as the best answer if you find it helpful.
Thanks
Akshay