0

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

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by hkb261
0

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.

0

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

0

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
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.