Solved

Regular expression for Asp.net text box conrol

Posted on 2010-11-22
8
593 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
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 200 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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 40 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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