phone and email - user input textbox validation

Rani

Well-known member
Joined
Nov 19, 2005
Messages
71
Programming Experience
Beginner
How would i do the validation in vb.net
for phone and email.
it's a text box i am using for both fields.
Thanks/Rani
 
You could use regular expressions, for example:

VB.NET:
Imports System.Text.RegularExpressions
 
Function IsValidPhone(ByVal str As String) As Boolean
    Dim pattern As String = "\d{3}-\d{3}-\d{4}"
    Dim re As RegEx = New RegEx(pattern)
 
    Dim m As Match = re.Match(str)
 
    Return m.Success
End Function
 
Last edited by a moderator:
VB.NET:
'Email Regex pattern:
Dim Pattern As String = "^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$"
 
I have a problem at this point
VB.NET:
    Return re.Success
I get success is not a member of 'System.Text.RegularExpressions.Regex'erroris this code applicable to VS 2005
 
.Success is a property of Match class (as used in MS example). IfYouSaySo should have return m.Success (so I fixed post2 now :))
 
Back
Top