473,327 Members | 2,074 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,327 software developers and data experts.

String Length Validation

A.M
Hi,

How can I use validation controls to check max length of string text boxes?

Thanks,
Alan
Nov 18 '05 #1
10 9462
Alan,

Use a regular expression validator to test for up to <max length>
repetitions of whatever characters you are willing to permit. For example,
to allow between 1 and 50 word or white-space characters, you might use the
following regular expression: ^[\w\s]{1,50}$

HTH,
Nicole

"A.M" <IH*******@sapm123.com> wrote in message
news:Ov**************@TK2MSFTNGP09.phx.gbl...
Hi,

How can I use validation controls to check max length of string text
boxes?

Thanks,
Alan

Nov 18 '05 #2
use the maxLength property of the textbox?

--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET)
Microsoft Certified Application Developer (.NET)
http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
"A.M" <IH*******@sapm123.com> wrote in message
news:Ov**************@TK2MSFTNGP09.phx.gbl...
Hi,

How can I use validation controls to check max length of string text boxes?
Thanks,
Alan

Nov 18 '05 #3
That will not prevent someone from submitting a longer string value from an
alternate UI. Server-side validation is a much more reliable way to ensure
that the submitted values meet expectations.

"Swanand Mokashi" <swanandATswanandmokashiDOTcomNOSPAM> wrote in message
news:uf*************@TK2MSFTNGP10.phx.gbl...
use the maxLength property of the textbox?

--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET)
Microsoft Certified Application Developer (.NET)
http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
"A.M" <IH*******@sapm123.com> wrote in message
news:Ov**************@TK2MSFTNGP09.phx.gbl...
Hi,

How can I use validation controls to check max length of string text

boxes?

Thanks,
Alan


Nov 18 '05 #4
Agreed

--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET)
Microsoft Certified Application Developer (.NET)
http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
"Nicole Calinoiu" <ni*****@somewhere.net> wrote in message
news:ed****************@TK2MSFTNGP09.phx.gbl...
That will not prevent someone from submitting a longer string value from an alternate UI. Server-side validation is a much more reliable way to ensure that the submitted values meet expectations.

"Swanand Mokashi" <swanandATswanandmokashiDOTcomNOSPAM> wrote in message
news:uf*************@TK2MSFTNGP10.phx.gbl...
use the maxLength property of the textbox?

--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET)
Microsoft Certified Application Developer (.NET)
http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
"A.M" <IH*******@sapm123.com> wrote in message
news:Ov**************@TK2MSFTNGP09.phx.gbl...
Hi,

How can I use validation controls to check max length of string text

boxes?

Thanks,
Alan



Nov 18 '05 #5
A.M

You can't relay on that because of security.

"Swanand Mokashi" <swanandATswanandmokashiDOTcomNOSPAM> wrote in message
news:uf*************@TK2MSFTNGP10.phx.gbl...
use the maxLength property of the textbox?

--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET)
Microsoft Certified Application Developer (.NET)
http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
"A.M" <IH*******@sapm123.com> wrote in message
news:Ov**************@TK2MSFTNGP09.phx.gbl...
Hi,

How can I use validation controls to check max length of string text

boxes?

Thanks,
Alan


Nov 18 '05 #6
Stop them from entering it in the first place..

try something like...

<asp:textbox id="SearchDescription" runat="server" CssClass="body_text" Rows="3" TextMode="MultiLine"
Width="173" onkeypress="return FilterMaxLength(event,this,60)" onpaste="return CheckPaste(this,60)"></asp:textbox>

function CheckPaste(o,max){
var maxLength = max;
// Get from clipboard
var data = window.clipboardData.getData("Text");

var CurrentLength = o.value.length + data.length;
if (CurrentLength > maxLength)
return false;
else
return true;
}

function FilterMaxLength(e,o,max){
// we must allow spaces , backspace etc to go through
var iKeyCode, strKey;

if (isIE) {
iKeyCode = e.keyCode;
} else {
iKeyCode = e.which;
}
strKey = String.fromCharCode(iKeyCode);
// Make sure we let special keys go through.
if (isSpecialKey(strKey))
return true;
var maxLength = max;
if(o.value.length > maxLength-1){
return false;
}
return true
}

"A.M" <IH*******@sapm123.com> wrote in message news:Ov**************@TK2MSFTNGP09.phx.gbl...
Hi,

How can I use validation controls to check max length of string text boxes?

Thanks,
Alan

Nov 18 '05 #7
Yes it is more reliable...

BUT pain in the a&*^*&^ for a user having to wait for a page to reload each
time..
3 things to do ..
1) Stop the user from entering it in the first place
2) before submit ensure it is NOT over the max length
3) check on server.

To stop the client side dont rely on the MS validatoin... it doesnt work for
most of your browser base..

try something like this for client side stuff...

<asp:textbox id="SearchDescription" runat="server" CssClass="body_text"
Rows="3" TextMode="MultiLine"
Width="173" onkeypress="return FilterMaxLength(event,this,60)"
onpaste="return CheckPaste(this,60)"></asp:textbox>

function CheckPaste(o,max){
var maxLength = max;
// Get from clipboard
var data = window.clipboardData.getData("Text");

var CurrentLength = o.value.length + data.length;
if (CurrentLength > maxLength)
return false;
else
return true;
}

function FilterMaxLength(e,o,max){
// we must allow spaces , backspace etc to go through
var iKeyCode, strKey;

if (isIE) {
iKeyCode = e.keyCode;
} else {
iKeyCode = e.which;
}
strKey = String.fromCharCode(iKeyCode);
// Make sure we let special keys go through.
if (isSpecialKey(strKey))
return true;
var maxLength = max;
if(o.value.length > maxLength-1){
return false;
}
return true
}

"Nicole Calinoiu" <ni*****@somewhere.net> wrote in message
news:ed****************@TK2MSFTNGP09.phx.gbl...
That will not prevent someone from submitting a longer string value from an alternate UI. Server-side validation is a much more reliable way to ensure that the submitted values meet expectations.

"Swanand Mokashi" <swanandATswanandmokashiDOTcomNOSPAM> wrote in message
news:uf*************@TK2MSFTNGP10.phx.gbl...
use the maxLength property of the textbox?

--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET)
Microsoft Certified Application Developer (.NET)
http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
"A.M" <IH*******@sapm123.com> wrote in message
news:Ov**************@TK2MSFTNGP09.phx.gbl...
Hi,

How can I use validation controls to check max length of string text

boxes?

Thanks,
Alan



Nov 18 '05 #8
Check out this article, this will help you.
http://www.extremeexperts.com/Net/To...neTextBox.aspx

--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com

"Darren Clark" <dc******@hotmail.com> wrote in message news:uF*************@TK2MSFTNGP11.phx.gbl...
Stop them from entering it in the first place..

try something like...

<asp:textbox id="SearchDescription" runat="server" CssClass="body_text" Rows="3" TextMode="MultiLine"
Width="173" onkeypress="return FilterMaxLength(event,this,60)" onpaste="return CheckPaste(this,60)"></asp:textbox>

function CheckPaste(o,max){
var maxLength = max;
// Get from clipboard
var data = window.clipboardData.getData("Text");

var CurrentLength = o.value.length + data.length;
if (CurrentLength > maxLength)
return false;
else
return true;
}

function FilterMaxLength(e,o,max){
// we must allow spaces , backspace etc to go through
var iKeyCode, strKey;

if (isIE) {
iKeyCode = e.keyCode;
} else {
iKeyCode = e.which;
}
strKey = String.fromCharCode(iKeyCode);
// Make sure we let special keys go through.
if (isSpecialKey(strKey))
return true;
var maxLength = max;
if(o.value.length > maxLength-1){
return false;
}
return true
}

"A.M" <IH*******@sapm123.com> wrote in message news:Ov**************@TK2MSFTNGP09.phx.gbl...
Hi,

How can I use validation controls to check max length of string text boxes?

Thanks,
Alan

Nov 18 '05 #9
Hi, Alan

Have you tried Nicole's suggestion of using Regular Expressions?

If that will not work for you, please expand on your scenario a bit so that
we understand your limitations.

Thank you for choosing the MSDN Managed Newsgroups,

John Eikanger
Microsoft Developer Support

This posting is provided “AS IS” with no warranties, and confers no rights.
--------------------
| From: "A.M" <IH*******@sapm123.com>
| Subject: Re: String Length Validation
| Date: Tue, 18 May 2004 21:43:53 -0400
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
|
| You can't relay on that because of security.
|
| "Swanand Mokashi" <swanandATswanandmokashiDOTcomNOSPAM> wrote in message
| news:uf*************@TK2MSFTNGP10.phx.gbl...
| > use the maxLength property of the textbox?
| >
| > --
| > Swanand Mokashi
| > Microsoft Certified Solution Developer (.NET)
| > Microsoft Certified Application Developer (.NET)
| > http://www.swanandmokashi.com/
| > http://www.swanandmokashi.com/HomePage/WebServices/
| > Home of the Stock Quotes, Quote of the day and Horoscope web services
| > "A.M" <IH*******@sapm123.com> wrote in message
| > news:Ov**************@TK2MSFTNGP09.phx.gbl...
| > > Hi,
| > >
| > > How can I use validation controls to check max length of string text
| > boxes?
| > >
| > > Thanks,
| > > Alan
| > >
| > >
| >
| >
|
|
|

Nov 18 '05 #10
A.M
Thank you John for follow up.I was aware of regular exressions and I was
hoping that I can find a less sophesticated method for just checking string
length.
I seems that regular exressions is the only choice.

Thanks Again,
Alan


"John Eikanger [MSFT]" <jo****@online.microsoft.com> wrote in message
news:5f**************@cpmsftngxa10.phx.gbl...
Hi, Alan

Have you tried Nicole's suggestion of using Regular Expressions?

If that will not work for you, please expand on your scenario a bit so that we understand your limitations.

Thank you for choosing the MSDN Managed Newsgroups,

John Eikanger
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights. --------------------
| From: "A.M" <IH*******@sapm123.com>
| Subject: Re: String Length Validation
| Date: Tue, 18 May 2004 21:43:53 -0400
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
|
| You can't relay on that because of security.
|
| "Swanand Mokashi" <swanandATswanandmokashiDOTcomNOSPAM> wrote in message
| news:uf*************@TK2MSFTNGP10.phx.gbl...
| > use the maxLength property of the textbox?
| >
| > --
| > Swanand Mokashi
| > Microsoft Certified Solution Developer (.NET)
| > Microsoft Certified Application Developer (.NET)
| > http://www.swanandmokashi.com/
| > http://www.swanandmokashi.com/HomePage/WebServices/
| > Home of the Stock Quotes, Quote of the day and Horoscope web services
| > "A.M" <IH*******@sapm123.com> wrote in message
| > news:Ov**************@TK2MSFTNGP09.phx.gbl...
| > > Hi,
| > >
| > > How can I use validation controls to check max length of string text
| > boxes?
| > >
| > > Thanks,
| > > Alan
| > >
| > >
| >
| >
|
|
|

Nov 18 '05 #11

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

Similar topics

10
by: David Graham | last post by:
Hi I have been busy going through the last weeks postings in an attempt to absorb javascript syntax (I guess it's not possible to just absorb this stuff in a passive way - I'm getting way out of...
1
by: Abra | last post by:
Is there any default maximal length for strings in the .NET inmplementation of XML schema validation (I used a XmlSchemaCollection in a XmlValidatingReader object) ? I am getting the following...
51
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct...
4
by: moondaddy | last post by:
Is there a asp.net validator control that validates the length of the text being entered or does everyone just write jscript for this? -- moondaddy@nospam.com
6
by: Edward | last post by:
I need to validate a text box entry, but ONLY if it is 17 characters, otherwise I have to ignore it. My regular expression for the validation is: ^(({9})()()(\d{6}))$ Can I adapt this to...
4
by: Trapulo | last post by:
I've a webservice with a string parameter. I call this webservice passing a string that is 1129 chars length. On the webservice, the received string is 1146 length (I tested sizes with...
17
by: Petyr David | last post by:
Just looking for the simplest. right now my perl script returns an error messge to the user if the date string is invalid. would like to do this before accessing the server. TX
14
by: Rob | last post by:
I am trying to perform client-side input validation for a textarea to determine that the number of characters doesn't exceed a certain length. Currently, I am just using str.length, but if the...
121
by: swengineer001 | last post by:
Just looking for a few eyes on this code other than my own. void TrimCString(char *str) { // Trim whitespace from beginning: size_t i = 0; size_t j; while(isspace(str)) {
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.