473,408 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

ValidationExpression that simulates the MaxLength property

As we probably know, the MaxLength property of the TextBox control only
works when the TextMode property is SingleLine or Password. I want to limit
the number of characters a user can enter into a MultiLine TextBox to 250. I
figured the best way to do this would be with a RegularExpressionValidator.
For my ValidationExpression I figured I would use:

..{0,250}

However, the . does not include the \n character. On the page:

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxfund/html/c82dc689-7e82-4767-a18d-cd24ce5f05e9.htm

there were a bunch of RegexOption members, one of which (the singleline
member) looked like it could do what I wanted. However, I was having trouble
understanding how to specify what options I wanted. If anyone could help me
here, I would appreciate it. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Jan 2 '07 #1
2 1355
Nathan,

Can you explain to us why using a regularExpressionValidator is better than
myTexbox.Text.Lenght 250

I am curious about that

Cor
"Nathan Sokalski" <nj********@hotmail.comschreef in bericht
news:O8**************@TK2MSFTNGP02.phx.gbl...
As we probably know, the MaxLength property of the TextBox control only
works when the TextMode property is SingleLine or Password. I want to
limit the number of characters a user can enter into a MultiLine TextBox
to 250. I figured the best way to do this would be with a
RegularExpressionValidator. For my ValidationExpression I figured I would
use:

.{0,250}

However, the . does not include the \n character. On the page:

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxfund/html/c82dc689-7e82-4767-a18d-cd24ce5f05e9.htm

there were a bunch of RegexOption members, one of which (the singleline
member) looked like it could do what I wanted. However, I was having
trouble understanding how to specify what options I wanted. If anyone
could help me here, I would appreciate it. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Jan 3 '07 #2
First of all, it is usually better to use one of the validator controls so
that in the code you can check whether everything passed validation by doing
something like

If Me.IsValid Then
End If

Your technique could be used with a CustomValidator, but CustomValidators
require a PostBack before the user can see the error message and ASP.NET
cannot attempt to generate JavaScript to perform client-side validation.
This is the best way of using one of the validators to limit the number of
characters I could find. Also, using a RegularExpressionValidator is less
code because you do not need to implement a ServerValidate event. In my
opinion, since the TextBox is a server-side control, there should be an
option for having this validation created automatically.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:O%****************@TK2MSFTNGP02.phx.gbl...
Nathan,

Can you explain to us why using a regularExpressionValidator is better
than
myTexbox.Text.Lenght 250

I am curious about that

Cor
"Nathan Sokalski" <nj********@hotmail.comschreef in bericht
news:O8**************@TK2MSFTNGP02.phx.gbl...
>As we probably know, the MaxLength property of the TextBox control only
works when the TextMode property is SingleLine or Password. I want to
limit the number of characters a user can enter into a MultiLine TextBox
to 250. I figured the best way to do this would be with a
RegularExpressionValidator. For my ValidationExpression I figured I would
use:

.{0,250}

However, the . does not include the \n character. On the page:

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxfund/html/c82dc689-7e82-4767-a18d-cd24ce5f05e9.htm

there were a bunch of RegexOption members, one of which (the singleline
member) looked like it could do what I wanted. However, I was having
trouble understanding how to specify what options I wanted. If anyone
could help me here, I would appreciate it. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/


Jan 3 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: mg | last post by:
I have a MultiLine TextBox (WebForm - C#) with the MaxLength property = 1000 but am able to type in an unlimited number of characters. Is there a way to limit the number of characters that can be...
4
by: hardcoded | last post by:
I have a textbox with TextMode set to MultiLine. I also have the MaxLength set to 255. This maxlength value seems to get ignored as the user can enter unlimited characters. Does the multiline...
3
by: RSB | last post by:
Hi Everyone, I have this TextBox with the TextMode="MultiLine". so now it does not validate the text in the TextBox for the MaxLength SO i have decided to execute a CustomValidator for this...
3
by: active | last post by:
I have a RichTextBox with MaxLength = 30 on a usercontrol. I can type more that 30 characters into it. Isn't the box supposed to stop accepting at 30??? Any idea what I may have wrong?
10
by: danthman | last post by:
I have a TextBox set up as follows: <asp:TextBox ID="SubjectTextBox" TextMode="MultiLine" MaxLength="100" Columns="50" Rows="2" Wrap="true" runat="server" />
3
by: h | last post by:
Hi, I have set my textbox's maxlength property to 1 , however it allow more than one word. Is there any settings that I am missing ? Thanks in advance Hardik Shah
3
by: skardian | last post by:
I am currently using the ChangePassword control for ASP.NET 2.0 to allow users to update or change their password as need be. However I am running into a problem with the Regular Expression...
2
by: Nathan Sokalski | last post by:
As we probably know, the MaxLength property of the TextBox control only works when the TextMode property is SingleLine or Password. I want to limit the number of characters a user can enter into a...
1
by: Mel | last post by:
Anyone know how I would retrieve the MaxLength property of a column in my Access Database table? I know how to retrieve table data, for example the "Quote #" field in my example code below, but I...
3
by: engineer | last post by:
Hi, I'm trying to control the maxlength property of a textbox in javascript. But it's not going into effect.This is my code HTML <input type=text id="txt_search_string" class=formtext...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.