cleanPhone(phoneNum)
Last updated June 24, 2011
Version: 0 | Requires: CF5 | Library: StrLib
Description:
Cleans up phone numbers that include leading 1s, text before and extension number or other characters. Returns in (###) ###-#### x### format. Uses PhoneFormat originally submitted by Derrick Rapley.
Return Values:
Returns a string.
Example:
<cfoutput>
#cleanPhone("1 312-555-1212 ext 1234")#
</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
phoneNum | Phone number string to "clean." | Yes |
Full UDF Source:
/**
* Strips unnecessary characters from phone numbers and returns a consistent looking phone number and extension, if necessary.
*
* @param phoneNum Phone number string to "clean." (Required)
* @return Returns a string.
* @author Jeff Horne (jeff.horne@trizetto.com)
* @version 0, June 24, 2011
*/
function cleanPhone(PhoneNum) {
var thisCleanPhone ="";
PhoneNum = ReReplace(trim(PhoneNum), "[^[:digit:]]", "", "all");
// Trim away leading 1 in phone numbers. No area codes start with 1
if (Left(Trim(PhoneNum),1) eq 1) {
PhoneNum = Replace(PhoneNum,'1','');
}
thisCleanPhone = PhoneFormat(Left(PhoneNum,10));
// if phone number is greater that 10 digits, use remaining digits as an extension
if (len(trim(PhoneNum)) gt 10) {
thisCleanPhone = thisCleanPhone &" x"& Right(PhoneNum,(len(trim(PhoneNum))-10));
}
return trim(thisCleanPhone);
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016