Code Snippets

  

Visual Basic Source Code


Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 117,613 VB Programmers for FREE! Ask your question and get quick answers from experts. There are 1,961 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! 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: 14,815

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.





Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month