Results 1 to 4 of 4

Thread: phone in a textbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Posts
    9

    Cool

    ok i have a textbox that the user is filling a phone number in it .
    i want to block writing letters and if im writing :

    if isnumeric(txtphone)= false then
    msgbox "incorrect number"

    else
    endif

    but i cant write ( - ) to separate the areacode from the number :
    954 - 65823154 what can i do without putting an extra textbox for the areacode?

    thanks

  2. #2
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    That's the onlt thing you can do, add anothe text box...b/c (to my knowledge) a dash a considered a letter so you will have to enable letters in order to have them. OR you can make it so after 3 digits are typed in, enable letters and when a dash (-) is placed, redisable them...it's more havoc than adding another text box but if you want to take that path...

    Gl,
    D!m
    Dim

  3. #3
    Lively Member nutstretch's Avatar
    Join Date
    May 2000
    Location
    UK
    Posts
    85
    I tend to you the keypress for that text box and something like

    if keyascii = 32 then
    else
    if keyascii = 45 then
    Else
    if keyascii = 8 then
    Else
    If (KeyAscii > 47) And (KeyAscii < 58) Then ' check to make sure a number has been pressed
    Else
    MsgBox ("Numbers only please")
    KeyAscii = 0
    End If
    End if
    End if
    End if

    the keyascii for space is 32 and i think the the keyascii for - is 45.
    keyascii for backspace = 8

    I hope this makes sense. I am new to VB but finmd that this works for me

    nuts

    if at first you don't succeed, drink the rest of the bottle and loop to the same place tomorrow

  4. #4
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Instead of a regular textbox, you can use the Masked Edit Control. (You get it in your toolbox by going to Project -> Components and checking "Microsoft Masked Edit Control 6.0".)

    To do the phone number thing, you can set the control's Mask property to:
    (###) ###-####

    "It's cold gin time again ..."

    Check out my website here.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width