SteveB Posted September 3, 2005 Posted September 3, 2005 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
comment Posted September 3, 2005 Posted September 3, 2005 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??).
SteveB Posted September 3, 2005 Author Posted September 3, 2005 (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 September 3, 2005 by Guest
comment Posted September 4, 2005 Posted September 4, 2005 (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 September 4, 2005 by Guest 1
SteveB Posted September 4, 2005 Author Posted September 4, 2005 (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 September 4, 2005 by Guest
comment Posted September 4, 2005 Posted September 4, 2005 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.
SteveB Posted September 4, 2005 Author Posted September 4, 2005 Thanks, Comment. That did the trick. Steve
Newbies simonsq Posted October 12, 2005 Newbies Posted October 12, 2005 Great solution. Thanks for the post. From a novice.
SteveB Posted November 21, 2005 Author Posted November 21, 2005 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
Lee Smith Posted November 22, 2005 Posted November 22, 2005 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
Meetloaf Posted December 12, 2006 Posted December 12, 2006 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!
mr_vodka Posted December 12, 2006 Posted December 12, 2006 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.
Lee Smith Posted December 12, 2006 Posted December 12, 2006 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
Meetloaf Posted December 13, 2006 Posted December 13, 2006 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?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now