473,385 Members | 1,470 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,385 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 1708
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.