hie i want the user to inset the email id in correct format. so i thought of using a masked text box. there are some predefined masks but none for email.
plz help

Recommended Answers

All 3 Replies

If it were me, since masked txt boxes are mainly used for numbers and symbols, I'd use regex and do a validation on it after the user hits the submit button. Here's a regex you can use, it's kind of scary long but it works really well, I've never had it fail.

([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})

If a match against that regex string returns no values, then you know they did not enter the email correctly and could give the user an error.

some explanation will be helpful.
how do insert it in the code.
thnx in advance

some explanation will be helpful.
how do insert it in the code.
thnx in advance

I would do the following:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If System.Text.RegularExpressions.Regex.IsMatch("([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})", Me.TextBox1.Text) Then
            MsgBox("Match Found")
        Else
            MsgBox("Match Not Found")
        End If
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.