[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

Help needed with textarea validation!!

(Marcus)

12/25/2002 10:26:00 PM

Hi!

I´m currently having a problem with my textarea regular expression
validator. I just want to check that the field does not contain more
than 255 characters.

My current regular expression validator has the following syntax:
<asp:RegularExpressionValidator runat="server"
ValidationExpression="^.{0,255}$" ControlToValidate="txt_Description"
ErrorMessage="Description cannot be more than 255 characters"
ID="txt_DescriptionRegularexpressionvalidator">*</asp:RegularExpressionValidator>

When text is written in the textarea without any returns (new line
(enter key)) the validator works fine but when the input is like below
it is invalid:

A little
description
text in three lines

What to do about this? Does anyone know a better validationexpression
that handles new line feed or do I have to use a customvalidator with
client javascript to check the fieldlength?

Regards

Marcus
3 Answers

Eric

12/18/2002 4:21:00 AM

0

Why not just use the MaxLength property and get rid of the validator? For
example:

<asp:TextBox id="txtMsg" TextMode="MultiLine" Rows="5"
Columns="100" MaxLength="255" AccessKey="M" />


"Marcus" <badkarspiloten@hotmail.com> wrote in message
news:25531a9c.0212160127.5586e09@posting.google.com...
> Hi!
>
> I´m currently having a problem with my textarea regular expression
> validator. I just want to check that the field does not contain more
> than 255 characters.
>
> My current regular expression validator has the following syntax:
> <asp:RegularExpressionValidator runat="server"
> ValidationExpression="^.{0,255}$" ControlToValidate="txt_Description"
> ErrorMessage="Description cannot be more than 255 characters"
>
ID="txt_DescriptionRegularexpressionvalidator">*</asp:RegularExpressionValid
ator>
>
> When text is written in the textarea without any returns (new line
> (enter key)) the validator works fine but when the input is like below
> it is invalid:
>
> A little
> description
> text in three lines
>
> What to do about this? Does anyone know a better validationexpression
> that handles new line feed or do I have to use a customvalidator with
> client javascript to check the fieldlength?
>
> Regards
>
> Marcus


Eric

12/20/2002 3:44:00 AM

0

Thanks for pointing that out, I hadn't noticed that. Anyway, here is a
solution. I've tested this and it does work. This example limits it to 20
characters for testing so adjust the limit in the ValidationExpression
property as needed. Note that hitting enter inserts a carriage return and
line feed character, so be sure to take that into account when looking at
the text in the control.


<asp:TextBox id="txtErrorMsg" TextMode="MultiLine" Rows="5"
Columns="100" AccessKey="M" runat="server" />
<asp:RegularExpressionValidator id="reVal" runat="Server"
ValidationExpression="(.|\r|\n){0,20}" ErrorMessage="Too many
characters"
ControlToValidate="txtErrorMsg" />


"Marcus" <badkarspiloten@hotmail.com> wrote in message
news:25531a9c.0212180057.e07a339@posting.google.com...
> Hi!
> Thanks for your reply!
>
> The maxlenght property for the textarea textbox is not a solution.
> Actually it does not work on textarea boxes because there is no
> maxlenght property for the <input type=textarea tag.
>
> Regards
>
> Marcus
>
>
> "Eric" <MagikNozeGoblin@HotMail.com> wrote in message
news:<atopju$9ci$1@ngspool-d02.news.aol.com>...
> > Why not just use the MaxLength property and get rid of the validator?
For
> > example:
> >
> > <asp:TextBox id="txtMsg" TextMode="MultiLine" Rows="5"
> > Columns="100" MaxLength="255" AccessKey="M" />
> >
> >
> > "Marcus" <badkarspiloten@hotmail.com> wrote in message
> > news:25531a9c.0212160127.5586e09@posting.google.com...
> > > Hi!
> > >
> > > I´m currently having a problem with my textarea regular expression
> > > validator. I just want to check that the field does not contain more
> > > than 255 characters.
> > >
> > > My current regular expression validator has the following syntax:
> > > <asp:RegularExpressionValidator runat="server"
> > > ValidationExpression="^.{0,255}$" ControlToValidate="txt_Description"
> > > ErrorMessage="Description cannot be more than 255 characters"
> > >
> >
ID="txt_DescriptionRegularexpressionvalidator">*</asp:RegularExpressionValid
> > ator>
> > >
> > > When text is written in the textarea without any returns (new line
> > > (enter key)) the validator works fine but when the input is like below
> > > it is invalid:
> > >
> > > A little
> > > description
> > > text in three lines
> > >
> > > What to do about this? Does anyone know a better validationexpression
> > > that handles new line feed or do I have to use a customvalidator with
> > > client javascript to check the fieldlength?
> > >
> > > Regards
> > >
> > > Marcus


(Marcus)

12/25/2002 10:27:00 PM

0

Hi!
Thanks for your reply!

The maxlenght property for the textarea textbox is not a solution.
Actually it does not work on textarea boxes because there is no
maxlenght property for the <input type=textarea tag.

Regards

Marcus


"Eric" <MagikNozeGoblin@HotMail.com> wrote in message news:<atopju$9ci$1@ngspool-d02.news.aol.com>...
> Why not just use the MaxLength property and get rid of the validator? For
> example:
>
> <asp:TextBox id="txtMsg" TextMode="MultiLine" Rows="5"
> Columns="100" MaxLength="255" AccessKey="M" />
>
>
> "Marcus" <badkarspiloten@hotmail.com> wrote in message
> news:25531a9c.0212160127.5586e09@posting.google.com...
> > Hi!
> >
> > I´m currently having a problem with my textarea regular expression
> > validator. I just want to check that the field does not contain more
> > than 255 characters.
> >
> > My current regular expression validator has the following syntax:
> > <asp:RegularExpressionValidator runat="server"
> > ValidationExpression="^.{0,255}$" ControlToValidate="txt_Description"
> > ErrorMessage="Description cannot be more than 255 characters"
> >
> ID="txt_DescriptionRegularexpressionvalidator">*</asp:RegularExpressionValid
> ator>
> >
> > When text is written in the textarea without any returns (new line
> > (enter key)) the validator works fine but when the input is like below
> > it is invalid:
> >
> > A little
> > description
> > text in three lines
> >
> > What to do about this? Does anyone know a better validationexpression
> > that handles new line feed or do I have to use a customvalidator with
> > client javascript to check the fieldlength?
> >
> > Regards
> >
> > Marcus