Click here to Skip to main content
14,825,162 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to validate a textbox that it should allow only certain characters and after the limit is reached the textbox should not allow entering characters in it.It can be done by Javascript but dont know how to do:confused:Anyone please help..
Updated 28-Jul-10 18:41pm

Go Through this code u will get it.....

<html xmlns="">
<head runat="server">
    <title>Without master page</title>
     <script type="text/javascript" src="js/JScript.js" ></script>
    <form id="form1" runat="server">
     <div> <br />
    <div id="lblMsg1">240 characters left</div>
    <asp:TextBox ID="TextBox1" runat="server" Height="50px"MaxLength="240"TextMode="MultiLine"Width="600px" ToolTip="Summary:(240 characters)"onkeyup="return validateLimit(this, 'lblMsg1', 240)"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
            ControlToValidate="TextBox1" Display="Dynamic"
    <br /><br /><br />
    <div id="lblMsg2">300 characters left</div>
    <asp:TextBox ID="TextBox2" runat="server" Height="50px" MaxLength="300" TextMode="MultiLine"Width="600px" ToolTip="Summary:(300 characters)"
                    onkeyup="return validateLimit(this, 'lblMsg2', 300)"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
            ControlToValidate="TextBox2" Display="Dynamic"
    <br /> <br />
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    <br />
abi1988 29-Jul-10 1:00am
But where is the JScript code?
koool.kabeer 29-Jul-10 4:53am
where is Jscript.js file?
Here you go:
1. Tie a JavaScript function Validate() on textbox onKeyUp
2. in function Validate:

    a. Use Regular Expression to check for specific characters.
    b. Use textbox Value length as a constraint for maximum characters allowed.
    Return true/false accordingly.

Try now!

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