Brian Dunning's FileMaker Custom Functions

phone.format ( Phone ; Format )

Format a phone number with format

  Average rating: 4.6 (31 votes) Log in to vote

Jesse Swensen   Jesse Swensen

Share on Facebook Share on Twitter

  Sample input:
phone.format ("5551212" ; "### (###) ###-####" );
phone.format ("55b51.2-12" ; "### (###) ###-####" );
phone.format ("8005551212" ; "### (###) ###-####" );
phone.format ("18005551212" ; "### (###) ###-####" );
  Sample output:
555-1212
555-1212
(800) 555-1212
1 (800) 555-1212

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

// Will format the number according to the given format.
// Fills in the format from right to left and if the number
// is longer than the format, the extra numbers will be
// prepended to the front of the formatted phone number.
// Any non-numeric characters in the phone number are ignored.

 

Comments

Jake DeGroot   Jake DeGroot
Oct 2, 2012
thanks will try this one.
 
Chuck   Chuck, North Carolina
Feb 5, 2013
I am very new to FM12 (FileMaker, too) This is exactly what I have been struggling with....where do I find FileMaker Advanced's Edit Custom Function window?
 
Maxime   Maxime, Shawinigan
Feb 6, 2013
Chuck : Go to "File" then "Manage" then "Custom Functions"
 
Jared   Jared, Orlando/FL
Aug 18, 2015
i get invalid parameter for "Phone"
 
Jenn   Jenn, Fullerton, CA
Apr 7, 2016
To Jared or anyone else, if you haven't figured it out yet, all calculations have parameters, that's the part within the parentheses... For example: Count (field), the parameter for the Count Function is "field". To simplify the above custom function, since I myself am pretty new to filemaker, and I'm not really sure about the format parameter above, let's just consider you want to make sure all phone numbers are formatted as such: (xxx)xxx-xxxx. In this case you just need one parameter "Text". I made my own custom function to mess around and prep to try and get certified ( which again only focuses on formatting like so: (xxx)xxx-xxxx.)it is as follows:

I entered the Edit Custom Function dialog, named the function "PhoneFormatting" and added a Function Parameter simply called "Text" (press green button to add) then the calculation was simply
"(" & Left(text;3) & ")" & Middle(text; 4;3) & "-" & Right(text;4)

Enter Manage database, pick the field you would like to apply custom function to, in my case the field was Cell_Phone, select Auto-enter calculation, enter PhoneFormatting (Text) and replace Text with the Cell_Phone field. You can also use "Self" if you prefer. For added security I added strict numeric data only under validation and a custom message if the user enters anything other than numeric values that stays "Please enter numbers only with no formatting."
This will not reformat populated fields, but if you're new to the game, hope that helps! :-)
 
Armen   Armen, Los Angeles/CA
Aug 16, 2016
Thank you for providing this code. What would be required to include an extension?
 
Hans   Hans, Spartanburg, SC
Sep 27, 2016
I get "An operator is expected here" on the first parenthesis after phone.format

phone.format ( NewNumber ; NewFormat ) & Right ( JustNumbers ; 1 ) ;

Also phone.format flagged as no function so i added it to the list.

any advice would be greatly appreciated.
 
Dennis   Dennis, Newberg
Dec 28, 2016
I'm not sure how to change the custom function based on the parameters for the phone number. Can someone send me a sample function that is clear where to place the parameters?

Thanks,

Dennis

dennis.littlefield@gmail.com
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Under construction. Email me your wish list for improvements.