Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 6555 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I just stepped up from v6 to v8 Advanced. I found this phone formatting function on Filemaker Advisor. It handles a number with and without an area code, so everything should be properly formatted. However, it seems to be missing a sub function ('PhoneFormatRight'), which I don't know what to do with so I can't get it to run. Here it is:

Case(

not IsEmpty(Format) or not IsEmpty(Phone); // coding after the "or" added by editor to prevent formatting of a blank Phone

Let(

[

NumbersOnly = Filter (Phone; "0123456789");

newFormat = Left(Format; Length(Format) - 1); // return all but the rightmost character

newNumber = Left(NumbersOnly; Length(NumbersOnly) - 1) // return all but the rightmost character

];

Case(

Right(Format; 1) = "#"; // Recurse & Return the rightmost character of the number

PhoneFormatRight(newNumber; newFormat) & Right(NumbersOnly; 1);

PhoneFormatRight(NumbersOnly; newFormat) & Right(Format; 1)

) // Close Case

) // Close Let

) // Close Case

Thanks, Steve

Posted

Why don't you tell us instead what you need to be done. It will be easier just to do it, rather than try to deduce what the author had in mind (TWO!! custom functions just to format a phone number??).

Posted (edited)

Sure, but why re-invent the wheel. This snippet came from John Mark Osborne (author of Scriptology).

Format a phone number: Sometimes the user inputs with an area code and sometimes without. Standard US Format (###) ###-#### or ###-####. In fact, to be done right, it should also handle a leading '1'. All of the functions I've seen either handle with or without an area code but not both. I didn't write the function, I only copied it.

Steve

Edited by Guest
Posted (edited)

I am not John Mark Osborne. However, I think I can do this without a custom function:

Let (

input = Filter (Phone ; "0123456789" )

;

Case ( input ;

Case (

Length ( input ) = 7 ;

Replace ( input ; 4 ; 0 ; "-" ) ;

Length ( input ) = 10 ;

Replace ( Replace ( Replace ( input ; 7 ; 0 ; "-" ) ; 4 ; 0 ; ") " ) ; 1 ; 0 ; "(" ) ;

Length (input ) = 11 and Left ( input ; 1 ) = "1" ;

Replace ( Replace ( Replace ( Right ( input ; 10 ) ; 7 ; 0 ; "-" ) ; 4 ; 0 ; ") " ) ; 1 ; 0 ; "(" ) ;

input & TextColor ( " too few or too many digits" ; 16711680 )

)

)

)

If you want to use a custom function, where the user can specify custom formatting such as (###) ###-####, try:

PhoneFormat ( phone ; format )

Let ( [

input = Filter ( phone ; "0123456789" ) ;

formatChar = Case ( Length ( format ) ; Right ( format ; 1 ) ; "#" ) ;

inputChar = Right ( input ; 1 ) ;

nextFormat = Left ( format ; Length ( format ) - 1 ) ;

nextFormatChar = Right ( nextFormat ; 1 ) ;

nextInput = Left ( input ; Length ( input ) - ( formatChar = "#" ) )

] ;

Case ( Length ( nextInput ) or Length ( input ) and nextFormatChar ≠ "#" ; PhoneFormat ( nextInput ; nextFormat ) )

&

Case ( formatChar = "#" ; inputChar ; formatChar )

)

Note that here the # characters are considered optional, so the length of input is not checked.

Edited by Guest
  • Like 1
Posted (edited)

Thanks, Comment. I don't see the purpose of doing it without a custom function, as this would need to be repeated for every phone number field. Nor do I necessarily see why the custom function should be passed a format since it will never change. Nevertheless, the custom function doesn't work...I defined Phone and Format, pasted the function, but I get a syntax error.

Steve

Edited by Guest
Posted

Sorry - the last parenthesis was way down, and I didn't catch it when copying. I have fixed it now.

Of course, you can turn any calc into a custom function. My remark was that no recursive calculation is required here - and certainly not two.

  • 1 month later...
  • 1 month later...
Posted

First you need 8 Advanced. Version 7 Developer might have custom functions...don't really know. Assuming you have 8 Advanced, select File/Define/Custom Functions. Highlight and copy to the clipboard the function displayed above. Paste into the Function body the stuff on the clipboard. You need to enter the function name and its parameters in their appropriate locations.

Steve

  • 1 year later...
Posted

Hello, I want to implement this into my solution. I know this may be a silly question, but how do you use the above code? I'm not sure where to put it :) Do you use it as a script?...or put it in a calculation somewhere?

Thanks!

Posted

Since you have FM 8 Advanced you can create Custom Functions.

Go to File --> Define --> Custom functions.

Once you create it, you can call the function in your formulas just like any other Native FM function.

Posted

If you are referring to the calculation by comment, there are a couple of ways. Both of which would be as a calculation. Since you have v8, you can actually have it part of a Auto Enter Calculation, or a separate field.

Lee

Posted

This is excellent! A mildly irrelevant, but important question I have is, Can I implement validation-type measures by using the Auto-enter field? (I ask this since Comment's code brought up red letters when too many or too few digits were entered)

What I am really interested in is validation using Instant Web Publishing. I would really like to do some simple validations on most fields there, but from what I've read, using FM's validation with instant web publishing takes quite a while if you are using it on multiple fields. Any suggestions/ideas/comments?

Thanks!

P.S. Do I have to apply these types of formatting functions before records are created? (since they are 'auto-enter') Or will they work with existing data?

This topic is 6555 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.