[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webcontrols

Validating a textbox with asp.net

Nikerz Inc

2/14/2004 8:25:00 PM

I'd like to validate my textbox1 with a phone number but I'd like to do it
with code in vb instead of doing it from the asp html window if that makes
sense!


3 Answers

Nikerz Inc

2/15/2004 4:24:00 AM

0

Hi there, that sounds great would you happen to have any code samples?? I'm
new to asp.net which doesn't help but I noticed that alot of sites are using
three text boxes for a phone number instead of one I wonder if that is from
the difficulty of making the code to validate the box.

"Ashish\" <abc@def.com> wrote in message
news:uIVOEQ38DHA.1640@TK2MSFTNGP11.phx.gbl...
> Why not extend the textbox class and handle appropiate (keydown /
> textchange) event ? or use a custom / wild card validators...
> HTH
> Ashish
>
> "Nikerz Inc" <nikerzinc@hotmail.com> wrote in message
> news:uz2hUiz8DHA.2812@TK2MSFTNGP11.phx.gbl...
> > I'd like to validate my textbox1 with a phone number but I'd like to do
it
> > with code in vb instead of doing it from the asp html window if that
makes
> > sense!
> >
> >
>
>


Traveller

2/15/2004 6:34:00 AM

0

Why not extend the textbox class and handle appropiate (keydown /
textchange) event ? or use a custom / wild card validators...
HTH
Ashish

"Nikerz Inc" <nikerzinc@hotmail.com> wrote in message
news:uz2hUiz8DHA.2812@TK2MSFTNGP11.phx.gbl...
> I'd like to validate my textbox1 with a phone number but I'd like to do it
> with code in vb instead of doing it from the asp html window if that makes
> sense!
>
>


Jos

2/15/2004 7:15:00 PM

0

Nikerz Inc wrote:
> Hi there, that sounds great would you happen to have any code
> samples?? I'm new to asp.net which doesn't help but I noticed that
> alot of sites are using three text boxes for a phone number instead
> of one I wonder if that is from the difficulty of making the code to
> validate the box.

No, it's rather to make it easy for the users to fill in the right format
(do I write slashes or dashes?)
As an alternative solution for this useability problem, you could show
an example next to the text box so that the user doesn't have to guess.

Validating phone numbers is actually very easy in asp.net:
1) add a RegularExpressionValidator to your form.
2) Make its ControlToValidate property point to the right text box
3) Modify the ErrorMessage to your own convenience
4) Set the ValidationExpression to your phone format, e.g.
"^\d{3}/\d{7}$" for the 012/3456789 format.

The rest is automatic, no code needed!
It will even do client-side validation (IE only).

If you're not familiar with regular expressions, you might want
to check www.regular-expressions.info, or download the free
Expresso program.

--

Jos