Brian Dunning's FileMaker Custom Functions

Mask ( input ; template ; placeholder )

Formats a numeric string to match a template supplied as a parameter (i.e. Phone, Social Security, Federal ID formats)

  Average rating: 3.9 (50 votes) Log in to vote

Geoffrey Gerhard   Geoffrey Gerhard - Show more from this author
Creative Solutions Incorporated
https://creativesltns.com

Share on Facebook Share on Twitter

  Sample input:
Mask ( "1234567890" ; "(###) ###-####" ; "#" )

Mask ( "1234567890123" ; "(###) ###-#### x." ; "#" )

Mask ( "333224444" ; "###-##-####" ; "#" )
  Sample output:
(123) 456-7890

(123) 456-7890 x.123

333-22-4444

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

UPDATED 06/01/2010--see below*

This function takes a string of numeric digits and formats them according to a template string made of non-numeric values (punctuation and/or text) combined with placeholder values to indicate where the numbers will go as they replace the placeholders. This...
Mask ( "1234567890" ; "(###) ###-####" ; "#" )
...returns...
(123) 456-7890

This function is designed to provide visual feedback when the user makes an invalid entry. Too few characters are indicated by BOLD RED placeholder values for every missing number. For example...
Mask ( "1234567" ; "(###) ###-####" ; "#" )
...would return...
(123) 456-7###
...with the three "#" characters in BOLD/RED

It also indicates too many characters when the template's last character is a placeholder. This...
Mask ( "1234567890123" ; "(###) ###-####" ; "#" )
...would return...
(123) 456-7890123
...with "(123) 456-7890" in the field's default text color/style and the characters "123" in BOLD/RED/STRIKE THROUGH, and " !" in the field's default text color/style to indicate that too many digits were entered. Such feedback may be expecially useful for Federal ID or Social Security Numbers.

This CF will add any extra digits to the end of the template when the last character is something other than a placeholder. Adding " x." to the template as follows...
Mask ( "1234567890123" ; "(###) ###-#### x." ; "#" )
...returns...
(123) 456-7890 x.123

Function Usage:
This function IS recursive.
Strip non-numeric characters from whatever string is passed to this function using the Filter() function like this...
Filter ( phoneNumberText ; 9876543210 )

There is a companion CF called "DialByWord" that converts uppercase letters into numbers, while ignoring lower-case letters that converts an entry like 800-CALL ATT to a the corresponding alpha-numeric string.

*Note: Updated one line in the function to account for "." as a separator among the placeholders when the input ends with one or more zeros. Thanks to Matt Lygo for the feedback!

 

Comments

Bart Bartholomay   Bart Bartholomay, Florida
Jan 9, 2009
I've tried this CF and for the simple 10-digit filtered input it seems to work OK, but add in the " x." as a template extension and it breaks down.
 
Geoffrey Gerhard   Geoffrey Gerhard, Creative Solutions Incorporated
Jul 1, 2009
Although I never imagined limiting an extension's length, I tried the template "(###) ###-#### x.###" and the CF returned the expected result from inputs with too few, the right number, and too many digits.

Perhaps Bart will provided more detail, since I cannot find a way to make the result "break down" when I "add in the ' x.'" to template. Anyone getting an unexpected result is welcome to contact me from my web site, (url listed above.)
 
Jean-Pierre Bergeron   Jean-Pierre Bergeron, Montreal, Quebec, Canada
Jan 6, 2013
Very useful, thanks
 
Bonnie Gable   Bonnie Gable, Charlotte, NC
Apr 24, 2013
The masks works great -- thanks for the info!

I do have a small issue. If I send the record (with the masked phone #) via email (i.e. as a PDF file) the two fields print one on top of each other (one with the mask format and the other without) and are unreadable. Do you know of a solution -- other than switching to a difference Layout -- which is not masked?

Thanks!!
 
Web   Web, Medford Oregon
Aug 14, 2016
I am working in filemaker 6, without the "Let" function available (.fp5).

I am trying to convert a phone number field with brackets like this:
(000) 000-0000

the converted value should be minus the brackets like this:
000-000-0000

all the research i see is for Filemaker 7 and newer.

Please advise.
 

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.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: