RegularExpressionValidator in codebehind

  • Thread starter Thread starter -=franz=-
  • Start date Start date
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
 
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
 
Indeed,
To do what you want to do, look at the
System.Text.RegularExpressions.Regex.IsMatch() shared method.

Karl
 
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
 
Back
Top