Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strip out leading spaces or zeros 1

Status
Not open for further replies.

lachesis

Technical User
Sep 25, 2002
138
NZ
I wondered if there was a shortcut to this problem. I started writing a function to do this but I've lost my way a bit... I believe there must be an easier way!!

I have three text fields:

IntSTD - max length 3
AreaSTD - max length 4
Number - max length 8

Together they would form an international phone number, as in: 61-2-95550001

Because they are text fields, a user can potentially (or by mistake) add leading zeros or spaces when they input each number. Also there are some countries with phone numbers shorter than the max length of 8.

Take a number in LA, USA for example. The international version is +1-310-55551234 (in my targeted format). But the user might put "001", "0310" into IntSTD and AreaSTD respectively.

I want to strip out the leading zeros or spaces for all combinations. Here are some other 'hairy' combinations to consider:

IntSTD, AreaSTD, Number
"01 ", "0001", " 551234"
" 1 ", " 001", "05551234"
" 1", " 01", " 5551234"

I started using the Instr function but I didn't want to write 6 different tests (2 chars x 3 fields).

Partially stumped...
L. [ponder]
 
Try using the CInt Function on AfterUpdate of the fields

Example:

IntSTD = CInt(IntSTD)
 
Or to avoid overflow using CLng

Example:

IntSTD = CLng(IntSTD)


 
Thanks. I lurve it when the best solutions are the simplest!!

[blue]strFullNumber = "+" & cstr(clng(IntSTD)) & "-" & cstr(clng(AreaSTD)) & "-" & cstr(clng(Number))[/blue]

thanks
L.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top