- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2017 09:31 AM
The Phone number field is great for international organizations, but for those of us who deal in the US, it's cumbersome and annoying. I'm looking for a simple way to force a database field to conform to (xxx) xxx-xxxx. I am unaware of anyway to do this via masking a string field (perhaps an advanced option?) nor am I able to do this with the phone number field without requiring a +1 or 1 in front of the (). Any help would be appreciated.
A possible solution would be to create a business rule on insert or update that reformats it, but again, I'd prefer front end masking as it acts like data validation as well.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2017 09:55 AM
You can run a client script (and/or transform script if you're doing an import) and use a regular expression to replace all non-numeric chars, strip the leading "1" etc:
var phoneNumber = current.phone + ''; // or g_form.getValue('phone') if in a client script
var digitOnlyRE = /\D/g;
var phoneNumberClean = phoneNumber.replace(digitOnlyRE, ''); // strip non-digit characters
// strip leading 1 if it exists
if (phoneNumberClean.length == 11 && phoneNumberClean[0] == '1'){
phoneNumberClean = phoneNumberClean.substring(1);
}
// put into final format
var phoneNumberFormatted = "(" + phoneNumberClean.substring(0,3) + ") " + phoneNumberClean.substring(3,6) + "-" + phoneNumberClean.substring(6);
[EDIT]
Above, lines 2-11 do all the work, so you can use them in an import, business rule, client script -- anywhere code is executed in SN.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2017 09:55 AM
You can run a client script (and/or transform script if you're doing an import) and use a regular expression to replace all non-numeric chars, strip the leading "1" etc:
var phoneNumber = current.phone + ''; // or g_form.getValue('phone') if in a client script
var digitOnlyRE = /\D/g;
var phoneNumberClean = phoneNumber.replace(digitOnlyRE, ''); // strip non-digit characters
// strip leading 1 if it exists
if (phoneNumberClean.length == 11 && phoneNumberClean[0] == '1'){
phoneNumberClean = phoneNumberClean.substring(1);
}
// put into final format
var phoneNumberFormatted = "(" + phoneNumberClean.substring(0,3) + ") " + phoneNumberClean.substring(3,6) + "-" + phoneNumberClean.substring(6);
[EDIT]
Above, lines 2-11 do all the work, so you can use them in an import, business rule, client script -- anywhere code is executed in SN.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2017 10:38 AM
Didn't even thing about doing an onChange client script, that'll totally work. Thanks!