Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
In my form I used textbox whose mode is multiple.I want to allow only 100 character (including number,special character and char).Maxlength will not work with textbox.What will be my Regular Expression?

ASP.NET
<asp:TextBox ID="tb" runat="server" TextMode="MultiLine" ></asp:TextBox>

//Regular Expression validator
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" 
    runat="server" ControlToValidate="tb" 
    ErrorMessage="Please enter maximum 100 charachters."
 SetFocusOnError="true" ValidationExpression="^[a-zA-Z.]{0,100}$">
    </asp:RegularExpressionValidator>


This include character only.I want number,spl char or any but count should not greater than 100.How to do that?
Posted
Updated 6-Jan-16 17:58pm
v3
Comments
PIEBALDconsult 6-Jan-16 23:59pm    
"Maxlength will not work with textbox"

Prove it.
Member 11589429 7-Jan-16 0:03am    
Maxlength work with textbox when textmode is singal not multiple.By default textmode is singal.
jgakenhe 7-Jan-16 0:34am    
You need to count the characters in JavaScript onkeyup and onkeydown: http://stackoverflow.com/questions/1334286/specifying-maxlength-for-multiline-textbox It is best if you use a function so you can reuse it.

Then if they have JavaScript turned off, you can validate the string length in your code behind on the button click event.

If I were at work, I'd provide my solution which I use quite often, but I won't be there for another 7 hours.

1 solution

If you want to allow any character, try simply
HTML
ValidationExpression="(.{0,100})"

or
HTML
ValidationExpression="^(.{0,100})$"
 
Share this answer
 
Comments
ridoy 7-Jan-16 1:03am    
a 5
Wendelius 8-Jan-16 1:35am    
Thank you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900