?
Solved

Regular expression for Asp.net text box conrol

Posted on 2010-11-22
8
Medium Priority
?
603 Views
Last Modified: 2012-05-10

I have a text box control and I need to restrict the text box input to no more than 255 characters. I created
a regular expression, however it is not correct. Can someone help me out? Here is my validation expression:
validationexpression="^.{0,255}$">


My actual Asp.net code looks something like, this but I know that the regular expression is not correct.

<ASP:RegularExpressionValidator id="regValInstructions" runat="server"
controltovalidate="txtMessage" textmode="multiline" tabindex="43"></ASP:TextBox>



validationexpression="^.{0,255}$">
<ASP:RegularExpressionValidator>
0
Comment
Question by:brgdotnet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 800 total points
ID: 34193754
The expression looks fine to me... shouldn't the code look like this though? (or was it just copying and pasting that jumbled it up?)

Try:
validationexpression="^[\s\S]{0,255}$">
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 34193756
Sorry... ignore the 1st line of my above comment. I meant to erase that and just suggest the pattern.
0
 
LVL 20

Expert Comment

by:informaniac
ID: 34193913
Why not use the MaxLength=255 property of textbox
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 20

Expert Comment

by:informaniac
ID: 34193917
Sry. missed out the multine thing..
0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 34194014
<asp:RegularExpressionValidator ID="txtConclusionValidator1" ControlToValidate="textBox" Text="Exceeding 255 characters" ValidationExpression="^[\s\S]{0,255}$" runat="server" />
0
 
LVL 29

Assisted Solution

by:Kumaraswamy R
Kumaraswamy R earned 160 total points
ID: 34194025
ASP.NET TextBox.MultiLine maxlength
-----------------------------------
Add following javascript

function Count(text,long)
 
{
var maxlength = new Number(long); // Change number to your max length.
if(document.getElementById('<%=TXTCount.ClientID%>').value.length > maxlength){
   text.value = text.value.substring(0,maxlength);
   alert(" Only " + long + " chars");
}
 


Where “textBox” is the asp text box ID.
Also add following events in your textbox.

onKeyUp="javascript:Count(this,200);" onChange="javascript:Count(this,200);"

Your textbox code should look like

 

<asp:TextBox ID="TXTCount" onKeyUp="javascript:Count(this,2);" onChange="javascript:Count(this,2);"  TextMode=MultiLine Columns="5" Rows="5" runat=server />
   
0
 
LVL 9

Expert Comment

by:abhinayp86
ID: 34196983
You can find many Regular Expressions here.. Just do a search in it

http://regexlib.com/Search.aspx?k=limit
0
 
LVL 9

Expert Comment

by:abhinayp86
ID: 34197022
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question