validating using regular expressions

dec21st

Active member
Joined
May 14, 2005
Messages
43
Programming Experience
3-5
just like how it can be done in asp.net, can i use regular expression to validate a vb.net application?

wat are the common or usual way to validate textbox?
 
PrivateSub TextBox1_Validating(ByVal sender AsObject, _

ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating

'code goes here

EndSub


or


Private Sub TextBox2_Validated(ByVal sender As Object, _

ByVal e As System.EventArgs) Handles TextBox2.Validated

'code goes here

End Sub



Cheers ;)
 
neway got it fix...

using regex. here's the code

VB.NET:
[size=2][color=#0000ff]Imports[/color][/size][size=2] System.Text.RegularExpressions
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] regexEmail [/size][size=2][color=#0000ff]As[/color][/size][size=2] Regex
 
[/size][size=2][color=#0000ff]If[/color][/size][size=2][color=#0000ff]Not[/color][/size][size=2] regexEmail.IsMatch(txtEmail.Text, "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*") [/size][size=2][color=#0000ff]Then
 
[/color][/size][size=2]ErrorProvider.SetError(txtEmail, "Invalid Email!")
 
[/size][size=2][color=#0000ff]Return[/color][/size][size=2][color=#0000ff]False
[/color][/size]
[size=2][color=#0000ff]Exit[/color][/size][size=2][color=#0000ff]Function
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If
 
[/color][/size]
 
Back
Top