Question Status

Verified
Damon (nomad) asked a question on 16 Mar 2015 5:49 PM

Hello Everyone:

Is there away to make a standard phone number to look the same way ie xxx-xxx-xxxx

Thanks

_damon

Reply
Verified Answer
Mahadeo Matre responded on 16 Mar 2015 6:21 PM

Hi..

you can use phone number  mask. .or when you are storing  number you can format and save number in required format..

Here are some links

mahadeomatre.blogspot.com/.../mask-phone-number-date-fields-in-crm.html

www.powerobjects.com/.../formatting-a-phone-field-in-crm-2013

Hope this will help..

Reply
Verified Answer
Mithilesh Kumar responded on 16 Mar 2015 8:57 PM

Hi Damon,

Here is code

// call this function to format any North American phone number(10 digit)
// in the following format: (xxx) xxx-xxxx
// pass context to the function
function FormatPhoneNo(context){
 try{
  var nvsField = context.getEventSource().getValue();
  var nvsTmp = nvsField;
  if (typeof (nvsField) != "undefined" && nvsField != null){
   nvsTmp = nvsField.replace(/[^0-9]/g, "");
   switch (nvsTmp.length){
    case 10:
     nvsTmp = "(" + nvsTmp.substr(0, 3) + ") " +
     nvsTmp.substr(3, 3) + "-" + nvsTmp.substr(6, 4);
     break;
    default:
     alert("Phone must contain 10 numeric digits.");
     break;
   }
  }
 context.getEventSource().setValue(nvsTmp);
 }catch(err){
  alert(err.message);
 }
}


Hope that helps

Thanks

Reply
Verified Answer
Mahadeo Matre responded on 16 Mar 2015 6:21 PM

Hi..

you can use phone number  mask. .or when you are storing  number you can format and save number in required format..

Here are some links

mahadeomatre.blogspot.com/.../mask-phone-number-date-fields-in-crm.html

www.powerobjects.com/.../formatting-a-phone-field-in-crm-2013

Hope this will help..

Reply
Verified Answer
Mithilesh Kumar responded on 16 Mar 2015 8:57 PM

Hi Damon,

Here is code

// call this function to format any North American phone number(10 digit)
// in the following format: (xxx) xxx-xxxx
// pass context to the function
function FormatPhoneNo(context){
 try{
  var nvsField = context.getEventSource().getValue();
  var nvsTmp = nvsField;
  if (typeof (nvsField) != "undefined" && nvsField != null){
   nvsTmp = nvsField.replace(/[^0-9]/g, "");
   switch (nvsTmp.length){
    case 10:
     nvsTmp = "(" + nvsTmp.substr(0, 3) + ") " +
     nvsTmp.substr(3, 3) + "-" + nvsTmp.substr(6, 4);
     break;
    default:
     alert("Phone must contain 10 numeric digits.");
     break;
   }
  }
 context.getEventSource().setValue(nvsTmp);
 }catch(err){
  alert(err.message);
 }
}


Hope that helps

Thanks

Reply