phone number validation

how to validate a phone numer in text box using vb 6

Page 1 of 1

1 Replies - 8535 Views - Last Post: 08 November 2006 - 08:11 AM Rate Topic: -----

#1 flower  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 08-November 06

phone number validation

Posted 08 November 2006 - 04:55 AM

Dim strTemp As String
   Dim strPhone As String
   Dim strExtension As String
   Dim intResult As Integer
   Dim cancel As Boolean
   
'   Const DefaultAreaCode = "080"
   
   strTemp = Replace(txtPhNumber.Text, "(", "")
   strTemp = Replace(strTemp, ")", "")
   strTemp = Replace(strTemp, "-", "")
   strTemp = Replace(strTemp, " ", "")
   strTemp = Replace(strTemp, "X", "x")
   
   intResult = InStr(1, strTemp, "x", vbTextCompare)
   If intResult > 0 Then
	  strExtension = Mid(strTemp, intResult + 1)
	  strPhone = Left(strTemp, intResult - 1)
   Else
	  strPhone = strTemp
   End If
   
   If Left(strPhone, 1) = "1" Then
	  strPhone = Mid(strPhone, 2)
   End If
   
   If Len(strPhone) <> 7 And Len(strPhone) <> 10 Then
	  MsgBox "Please enter a valid telephone number.", vbExclamation
	  txtPhNumber.Text = ""
	  txtPhNumber.SetFocus
	  cancel = True
	  Exit Sub
   End If
	  
   If Len(strPhone) = 7 Then
	  strPhone = DefaultAreaCode & strPhone
   End If
   
   txtPhNumber.Text = "(" & Left(strPhone, 3) & ") " _
	  & Mid(strPhone, 4, 3) & "-" _
	  & Right(strPhone, 4)
   
   If strExtension <> "" Then
	  txtPhNumber.Text = txtPhNumber.Text & " x" & strExtension
   End If


edit: added [code] tags ~ jayman9

Is This A Good Question/Topic? 0
  • +

Replies To: phone number validation

#2 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: phone number validation

Posted 08 November 2006 - 08:11 AM

Moved tyo visual basic
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1