April 1, 200520 yr I have a text field for phone number. Is there a way to set the format like xxx-xxx-xxxx? In another word, is there a way to set 3 spaces, put a dash in, another 3 spaces, put another dash in, then 4 spaces? So users can only fill in the spaces. It's to control the data integrity.
April 1, 200520 yr This is the script I use to format phone numbers. It check the length and strips away any unwanted character like periods, brackets. Then it reconstructs then number with hypens. It needs to go into a caculation field in FP6. My sample script uses a field called HomePhone to get the data. Hope that helps some. If( Length( NumToText( TextToNum( Substitute( Substitute( Substitute( Substitute( HomePhone , " " , "" ) , "." , "" ) , ")" , "" ), "(" , "" ) ) ) ) = 10, Left( NumToText( TextToNum( Substitute( Substitute( Substitute( Substitute( HomePhone , " " , "" ) , "." , "" ) , ")" , "" ), "(" , "" ) ) ), 3 ) & "-" & Middle( NumToText( TextToNum( Substitute( Substitute( Substitute( Substitute( HomePhone , " " , "" ) , "." , "" ) , ")" , "" ), "(" , "" ) ) ) , 4 , 3 ) & "-" & Right( NumToText( TextToNum( Substitute( Substitute( Substitute( Substitute( HomePhone , " " , "" ) , "." , "" ) , ")" , "" ), "(" , "" ) ) ) , 4 ), "Error" ) I attached a working FP6 sample. phone.zip
April 1, 200520 yr If you know that's the ONLY way the phone numbers should show up, then you should set up field validation as well. Validation is a great thing for dates, to force the user(s) to enter in a four digit year. Not having a 4 digit year has cause way too many headaches, especially when exporting/importing. I'm supposing that your solution will not have any "forein" numbers, so country codes and the such aren't needed.
April 1, 200520 yr Yuchieh's post showed a 10 digit number format. So that what I went with. The calculation could be modified to show any format desired. And I somewhat included a validation portion to the caculation.
April 1, 200520 yr Take a look at the file I posted with this thread: It's located half way down the page with: Click here to go There are some other tips there that should be of help also. HTH Lee
April 4, 200520 yr Author Thanks all for the responses. For Guillpro, the calculation works great. However, it requires another field to reflect the number entry. Is there a way to correct the number in it's own field? For BrentHedden, there is no international numbers, only 10 digits plus tow dashes. I am not sure about the validation in the field. Even I limit to 10 or 12 digits in the fields, it still doesn't limit the "format" such as using ( ) around area cord, does it?
April 4, 200520 yr Author yes, still looking. bunch of stuff, not sure which one to apply on my case yet. thanks
April 4, 200520 yr This one., by me. [color:"blue"]#82216 - 09/23/03 01:29 PM Attachment where I said this [color:"blue"] Why not do something along the lines of this sample of mine. Lee
April 4, 200520 yr Hi, Can't remember were I borrowed this from I think it was a post on this forum. The solution I used this in stored numbers in one field so this worked for me. The formatting is triggered via script upon exiting the field and will handle extensions. Let( [TempNum= Filter(Get ( ActiveFieldContents ); "0123456789"); //remove leading 1 Num = If(Left(tempnum;1) = 1; Middle(tempnum;2;99); tempnum); Phone = "("& Left(num;3) & ") "& Middle(num;4;3) & "-"& Middle(num;7;4) & // if it exceeds a length assume it is an extension If(Length(num)> 10; " x"&Middle(num;11;99);"")]; If(Length ( Num ) < 10; // if number is to short less than 10 digits display it in red as error TextColor ( phone & "Input Error" ; RGB ( 255 ; 0 ; 0 )); // remove color format TextColor ( phone ; RGB (0 ; 0 ; 0 ))))
April 4, 200520 yr Author yes, I saw that one. that's similar to sample quillpro posted here. The final phone number is the calculation result of three other fields in your sample. However, I have only one field "phone". I would like the entered number either automatically formatted as xxx-xxx-xxxx, or at least send a warning message if the format is not correct and stop the process. I put some valdiation calculation, but it is not working. Thanks test.zip
April 4, 200520 yr You can not create a circular definition in FM6. Meaning the field can not reference itself in the calculation. You can do this in FM7. As far I as know you would need to use a script to set a global field with the phone # data as entered. Then reformat the global field a insert it back to the phone # field. Use could use a button to launch the script. If there's another or better way I don't know it.
April 4, 200520 yr The calculation is actually the result of only one field. The same field that is used for number entry is the same field that gets formatted. I included a one field single script example if you want to take a look at it. NumberFormat.zip
April 4, 200520 yr YuChieh is using FM6 not 7. Your example is a FM7 file. As I mentioned before you can not do it with FM6. If I am incorrect, someone please post a FM6 example.
April 4, 200520 yr I don't have the sample on this computer, so I CAN'T check it, but I remember that one of them I posted, and I'm sure it was this one, had a layout showing how to STACK the fields to appear as you want. Let me know if this doesn't have a Layout that shows how to stack the fields in it, and I'll dig up the other one, or point you to it on the Forum. If this method doesn't sound like what you want to do, please let me know and I'll stop wasting my time on this thread, and move on to someone else's needs. Lee
April 5, 200520 yr This may be what quill is saying you can't do in 6, so it may not work. In 7, it seems to work for me. In the field phone, select validate by calculation as follows: If(Length ( Filter(Phone;"0123456789"))=10;1;0) Hope that helps.
Create an account or sign in to comment