You need to sign in to do that
Don't have an account?
Premanath
How to write apex class for formated phone number
Hi All,
I have some issue like-- > I have two fields
phone number-- +91-(08)/9855664555
country code ---> 110
third field is should be automatically comes when we fill above two fields like this :
formatedph: 11091089855664555
Means write a wrapper class it call from any where(trigger) . and print without special char.
Thank you guys,
Hi,
Cant you use simple formula field and replace special characters with blank using "substitute" method of TEXT.
The code below strips out all non digits and formats to 10 digits if 10 long, otherwise returns original
But you can just use the regex/replace to give you back a digits only number:
String fphone = cphone.replaceAll('\\\\D','');
public static String formatphonenumber(String cphone) {
String fphone = cphone.replaceAll('\\\\D','');
if (fphone.length() == 10) {
fphone = formatphonenum(fphone);
return fphone;
}
else {
return cphone;
}
}
static String formatphonenum (String s) {
s = '(' + s.substring(0, 3) + ') ' + s.substring(3, 6) + '-' + s.substring(6);
return s;
}
public String getFormattedPhoneNum() {
if(phoneNumber == null){
return '';
}
else{
String s = '(' + phoneNumber.substring(0, 3) + ')' + phoneNumber.substring(3, 6) + phoneNumber.substring(6);
return s;
}
Result:(000)-000-0000