The routine can be used as-is to format numbers as:
234-5678 or 234-567-8900
regardless of how the user enters the number.
This method allows the user to type numbers any way they wish (they'll usually do it with no special characters at all because that's the fastest way) or to copy and paste numbers from some other source with needing to 'fix' them first.
It can be modified to create any format you prefer. One modification I made was to create a version that uses parenthesis around the area code.
Use this in the CanWrite Field event to format the phone number before saving the record:
A_field_value = Phone_dash( A_field_value )
Then use the function in scripted finds something like this:
234-5678 or 234-567-8900
regardless of how the user enters the number.
This method allows the user to type numbers any way they wish (they'll usually do it with no special characters at all because that's the fastest way) or to copy and paste numbers from some other source with needing to 'fix' them first.
It can be modified to create any format you prefer. One modification I made was to create a version that uses parenthesis around the area code.
Code:
FUNCTION Phone_dash AS C (Phone_in AS C ) 'Description:Adds dashes to phone numbers as necessary and removes leading "1"s. Assumes 333-444-1234 output format will always be valid. DIM phone_w as C phone_w = remspecial( phone_in ) 'Define the 'working' number. IF phone_w = "" Phone_dash = phone_w EXIT FUNCTION END IF 'Assume any number beginning with 01 is international and leave it as-is. IF left(phone_w,2)="01" Phone_dash = Phone_in EXIT FUNCTION END IF 'Remove any leading 1 that might be for long distance. 'Left the ability to start an area code or exchange with "1" because of a ' conversion routine I use to "encrypt" phone numbers. (Although, it would be ' better to change the "encryption" too so all beginning 1s becomes 2s...) IF left(phone_w,1)="1" .and. len(phone_w)=11 phone_w = substr(phone_w,2) END IF phone_w = stuff( phone_w, 4, 0, "-" ) IF len(trim(phone_w))>8 phone_w = stuff( phone_w, 8, 0, "-" ) END IF Phone_dash = phone_w END FUNCTION
A_field_value = Phone_dash( A_field_value )
Then use the function in scripted finds something like this:
Code:
input_phone = ui_get_text( "PHONE NUMBER?", "Enter Bill-to phone number." ) IF input_phone = "" END' END IF parentform.index_set( "Cust_fone_" ) parentform.find( Phone_dash( input_phone ) )
Comment