We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,610 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

how to check the format of input data while the user enteres data in text b

I have vb form tht accepts user data.I need to check whether user enters emailid in the correct format ?Please provide suggestion .Thanks in advance

2
Contributors
3
Replies
6 Days
Discussion Span
3 Months Ago
Last Updated
28
Views
Question
Answered
ponnu
Light Poster
39 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

try this
first define a function

Private Function IsValidEmailAddress(ByVal sEmail As String, Optional ByRef sReason As String) As Boolean
   sEmail = LCase(Trim(sEmail))
   If Len(sEmail) < 7 Then
      sReason = "Too short"
   ElseIf sEmail Like "*[!0-9a-z@._+-]*" Then
      sReason = "Invalid character"
   ElseIf Not sEmail Like "*@*.*" Then
      sReason = "Missing the @ or ."
   ElseIf sEmail Like "*@*@*" Then
      sReason = "Too many @"
   ElseIf sEmail Like "[@.]*" Or sEmail Like "*[@.]" _
      Or sEmail Like "*..*" Or Not sEmail Like "?*@?*.*?" Then
      sReason = "Invalid format"
   Else
      Dim n As Integer
      n = Len(sEmail) - InStrRev(sEmail, ".")
      If n > 3 Then
         sReason = "Suffix too long"
      ElseIf n < 2 Then
         sReason = "Suffix too short"
      Else
         sReason = Empty
         IsValidEmailAddress = True
      End If
   End If
End Function

here call it (Normally On the lostfocus event)

Private Sub Text1_LostFocus()
Dim bool As Boolean, reason As String
bool = IsValidEmailAddress(Me.Text1.Text, reason)
If (bool <> True) Then
MsgBox reason
End If
End Sub

Hope this helps you . . .

rishif2
Junior Poster
175 posts since Dec 2012
Reputation Points: 54
Solved Threads: 34
Skill Endorsements: 3

its showing error for proper format of email

ponnu
Light Poster
39 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

thank you for resolving :)kindly ignore the former message

ponnu
Light Poster
39 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 3 Months Ago by rishif2

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0615 seconds using 2.68MB