September 3, 200520 yr 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
September 3, 200520 yr 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??).
September 3, 200520 yr Author 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 September 3, 200520 yr by Guest
September 4, 200520 yr 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 September 4, 200520 yr by Guest
September 4, 200520 yr Author 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 September 4, 200520 yr by Guest
September 4, 200520 yr 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.
November 21, 200520 yr Author 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
November 22, 200520 yr The Custom Function is only available in the Developer Edition of FileMaker (i.e. Developer 7, and Advance in V8). These sites sponsored by, Brian Dunning and Cleveland Consulting have several examples that others have provided, and this description by Court Bowman says it pretty good. HTH Lee
December 12, 200619 yr 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!
December 12, 200619 yr 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.
December 12, 200619 yr 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
December 13, 200619 yr 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?
Create an account or sign in to comment