RegularExpressionValidator in codebehind

F

-=franz=-

dim value as string = "noemail"
Dim emailc As New RegularExpressionValidator
emailcc.ControlToValidate = value
emailcc.ValidationExpression = "^[\w-\.]+@([\w-]+\.)+[\w-]{2,3}$"
Dim x As String = emailc.IsValid

why it gives me "true"?
where is the mistake?

grazie
franz
italy
______________
Franz
www.ewave.it/franz_photos

- La fama degli eroi spetta un quarto alla loro audacia; due
quarti alla sorte: e l'altro quarto ai loro delitti. -- Ugo Foscolo
 
S

Shiva

Hi,
The default value for IsValid is true. The actual value will be available
only after you called the Validate method on the validator control.
Also, the ControlToValidate should be the ID of the server control to be
validated. Not the string value you want to validate.

dim value as string = "noemail"
Dim emailc As New RegularExpressionValidator
emailcc.ControlToValidate = value
emailcc.ValidationExpression = "^[\w-\.]+@([\w-]+\.)+[\w-]{2,3}$"
Dim x As String = emailc.IsValid

why it gives me "true"?
where is the mistake?

grazie
franz
italy
______________
Franz
www.ewave.it/franz_photos

- La fama degli eroi spetta un quarto alla loro audacia; due
quarti alla sorte: e l'altro quarto ai loro delitti. -- Ugo Foscolo
 
K

Karl

Indeed,
To do what you want to do, look at the
System.Text.RegularExpressions.Regex.IsMatch() shared method.

Karl
 
F

-=franz=-

thankyou guys!
ive done!
i was using a wrong class
at the end this was the correct one:

Dim regex As New
System.Text.RegularExpressions.Regex("^[\w-\.]+@([\w-]+\.)+[\w-]{2,3}$")

Dim match As System.Text.RegularExpressions.Match

match = regex.Match(ExistingEmail)

If Not match.Success Then

MsgErrore = MsgErrore & "Not correct email!<br>"

End If


______________
Franz
www.ewave.it/franz_photos

- La fama degli eroi spetta un quarto alla loro audacia; due
quarti alla sorte: e l'altro quarto ai loro delitti. -- Ugo Foscolo

Karl said:
Indeed,
To do what you want to do, look at the
System.Text.RegularExpressions.Regex.IsMatch() shared method.

Karl


Shiva said:
Hi,
The default value for IsValid is true. The actual value will be available
only after you called the Validate method on the validator control.
Also, the ControlToValidate should be the ID of the server control to be
validated. Not the string value you want to validate.

dim value as string = "noemail"
Dim emailc As New RegularExpressionValidator
emailcc.ControlToValidate = value
emailcc.ValidationExpression = "^[\w-\.]+@([\w-]+\.)+[\w-]{2,3}$"
Dim x As String = emailc.IsValid

why it gives me "true"?
where is the mistake?

grazie
franz
italy
______________
Franz
www.ewave.it/franz_photos

- La fama degli eroi spetta un quarto alla loro audacia; due
quarti alla sorte: e l'altro quarto ai loro delitti. -- Ugo Foscolo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top