Code Snippets

  

Visual Basic Source Code


Welcome to Dream.In.Code
Become a VB Expert!

Join 149,026 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,940 people online right now. Registration is fast and FREE... Join Now!





TextBox Telephone Number Formatting

isual Basic provides only the Number Format Option in DataFormat Property of a Text Box. Using the "Number" option allows people to type negative numbers and numbers with decimals.So here is the code that you should insert in the Text Box's KeyPress Function so that the text-box will accept only phone-numbers.

Submitted By: born2c0de
Actions:
Rating:
Views: 16,156

Language: Visual Basic

Last Modified: March 16, 2005

Snippet


  1. ' Assuming that Text1 is the Text Box where you want the 'user to enter the telephone number, here is the KeyPress 'Event Function that does the trick.
  2. '                            -Sanchit Karve
  3. '                          born2c0de@hotmail.com
  4.  
  5. Private Sub Text1_KeyPress(KeyAscii As Integer)
  6.    If Len(Text1.Text) = 0 And KeyAscii = 45 Then
  7.       KeyAscii = 0
  8.    End If
  9.  
  10.    If KeyAscii >= 58 Or (KeyAscii <= 47 And KeyAscii <> 45 And KeyAscii <> 8 And KeyAscii <> 13) Then
  11.       KeyAscii = 0
  12.    End If
  13. End Sub

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.




Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month