how to create a RegularExpressionValidator in runtime ? ?

  • Thread starter Ricardo Corsi P. Cesar
  • Start date
R

Ricardo Corsi P. Cesar

Hi, i looking for example in asp.net (VB) to make the
RegularExpressionValidator in runtime in my code behind.

I found some similars codes, but nothing in VB..

thanks!
 
R

Ricardo Corsi P. Cesar

Sure, here we go:

Public Shared Function Test(ByVal campo As TextBox)
Dim rf As New RegularExpressionValidator
rf.ID = "rf"
rf.Enabled = True
rf.Visible = True
rf.Display = ValidatorDisplay.Dynamic
rf.ErrorMessage = "You must enter a value"
rf.Text = "*"
rf.ValidationExpression = "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
rf.ControlToValidate = (campo.ID)
rf.EnableClientScript = True
rf.EnableViewState = False
rf.Validate = campo
End Function

but this code above, it seems to do nothing when i use it on a button (on
click event). Something is missing to this simple code work fine.

could you help me up ?
 
N

Nick Hertl

I'm having trouble getting a RegularExpressionValidator to work at all
because I've never needed one, but it looks like you might need to make
this change:
rf.ValidationExpression = "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
rf.ValidationExpression = @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"

That magical "@" will make the "\" chars in your regexp literal instead of
escape characters.

If you are still having trouble, let me know and I will dig deaper to see
if I can get you a solid example.

----------------
This posting is provided "AS IS" with no warranties, and
confers no rights.

Please do not send e-mail directly to this alias. This
alias is for newsgroup purposes only.

Thanks
Nick

--------------------
From: "Ricardo Corsi P. Cesar" <[email protected]>
References: <[email protected]>
Subject: Re: how to create a RegularExpressionValidator in runtime ? ?
Date: Wed, 26 Nov 2003 13:41:29 -0200
Lines: 48
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 200-171-96-217.speedyterra.com.br 200.171.96.217
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:193512
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Sure, here we go:

Public Shared Function Test(ByVal campo As TextBox)
Dim rf As New RegularExpressionValidator
rf.ID = "rf"
rf.Enabled = True
rf.Visible = True
rf.Display = ValidatorDisplay.Dynamic
rf.ErrorMessage = "You must enter a value"
rf.Text = "*"
rf.ValidationExpression = "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
rf.ControlToValidate = (campo.ID)
rf.EnableClientScript = True
rf.EnableViewState = False
rf.Validate = campo
End Function

but this code above, it seems to do nothing when i use it on a button (on
click event). Something is missing to this simple code work fine.

could you help me up ?
 

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

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top