Format Phone Number

Format Phone Number

Here are a couple of sample functions to help you clean up phone numbers.

Function ScriptedField
    dim oldphone
 dim phone
 dim xPos
 dim plusPos
 dim extension
    oldphone="@@ORG:phone_office@@"
 phone=oldphone

 if len(phone) <> 0 then
  'Remove all non-numberic characters except the x and + sign.
  With CreateObject("vbscript.regexp")
   .Pattern = "[^0-9x+]"
   .Global = True
   phone = .Replace(phone, "")
  End With

  plusPos = inStr(1,phone,"+")
    
  if plusPos > 0 then
   'Ignore foreign phone numbers.
   ScriptedField = oldphone
  else
   'break off the extension.
   xPos = inStr(1,LCase(phone),"x")
   if xPos > 0 then
    extension = Trim(Right(LCase(phone), (Len(phone) - (xPos) + 1)))
    phone = Trim(Left(phone, (xPos - 1)))
   Else
    extension = ""
   End If
   'format non-foreign phone numbers and phone numbers without an extension.
   if Len(phone)=11 and Left(phone,1)="1" then 
    phone = Mid(phone,2)
    ScriptedField = mid(phone,1,3) & "-" & mid(phone,4,3) & "-" & mid(phone,7) & extension
   elseif Len(phone)=10 then
    ScriptedField = mid(phone,1,3) & "-" & mid(phone,4,3) & "-" & mid(phone,7) & extension
   else
    ScriptedField = oldphone
   end if
  end if
    end if
End Function
    • Related Articles

    • Twilio Connector

      Twilio Authentication The use of the Twilio connector requires a Twilio account. Instead of a username and password, you sign into the API with using your Account SID and a secret Auth Token that is assigned to you. This can be retrieved from the ...
    • SugarCRM SOAP Connector

      SugarCRM SOAP Origin Note that the tab in Creatio Connect is labelled simply "SugarCRM". Sample Origin Filters Mapping Attachments In Sugar, Attachments are stored as Notes. To attach a file to a Note, simply run and Insert, Update or Update/Insert ...
    • Zoho CRM Connector

      Additional Documentation This Connector is based on the Zoho CRM ADO.NET Provider by CData. For additional help, including Connection String parameters, please see: https://cdn.cdata.com/help/CZG/ado/ Authenticating to Zoho CRM The provider is ...
    • Scripting Class Object

      From within VBScript operations (ScriptedVariable, VBScriptProcedure, ScriptedField) in additional to normal VBScript functions, the developer has access to a custom “Connect Creatio” class. The tables below define its usage. This class may also be ...
    • Facebook Connector

      Additional Documentation This Connector is based on the Facebook ADO.NET Provider by CData. For additional help, including Connection String parameters, please see: https://cdn.cdata.com/help/RBG/ado/ Establishing a Connection Authenticating to ...