• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 623
  • Last Modified:

Regular expression for Asp.net text box conrol


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
brgdotnet
Asked:
brgdotnet
  • 2
  • 2
  • 2
  • +1
2 Solutions
 
Terry WoodsIT GuruCommented:
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
 
Terry WoodsIT GuruCommented:
Sorry... ignore the 1st line of my above comment. I meant to erase that and just suggest the pattern.
0
 
informaniacCommented:
Why not use the MaxLength=255 property of textbox
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
informaniacCommented:
Sry. missed out the multine thing..
0
 
Kumaraswamy RCommented:
<asp:RegularExpressionValidator ID="txtConclusionValidator1" ControlToValidate="textBox" Text="Exceeding 255 characters" ValidationExpression="^[\s\S]{0,255}$" runat="server" />
0
 
Kumaraswamy RCommented:
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
 
abhinayp86Commented:
You can find many Regular Expressions here.. Just do a search in it

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now