Java script validation RRS feed

  • Question

  • User898390756 posted

    hi friends..,

     how to count a charecter in text box i need onl allow 200 charecter for text box by java script


    please help me..

    Saturday, October 29, 2011 1:49 AM


All replies

  • User1890471016 posted

    try this:


    Hope this will help you

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 29, 2011 1:58 AM
  • User-665004399 posted


    refer this




    Saturday, October 29, 2011 2:44 AM
  • User-784583665 posted

    you can get more information here 

    function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) // if too long...trim it!
    field.value = field.value.substring(0, maxlimit);
    // otherwise, update 'characters left' counter
    countfield.value = maxlimit - field.value.length;
    <textarea name=message wrap=physical cols=28 rows=4 onKeyDown="textCounter(this.form.message,this.form.remLen,125);" onKeyUp="textCounter(this.form.message,this.form.remLen,125);"></textarea>



    Saturday, October 29, 2011 4:45 AM
  • User854688209 posted

    Why don't you use max length propery in the input text box, user won't able to enter more than 200 characters in the text box.

    <input type="text" name="xyz" maxlength="200" size="4" />

    Saturday, October 29, 2011 5:36 AM
  • User555306248 posted

    What there should be is that maxlength property should be disabled when textmode is multiline.But it is not implemented

    So You can use simple regular expression validator to overcome for setting maxlenth of your field

    <asp:RegularExpressionValidator ID="rgConclusionValidator2"
                                    ControlToValidate="txtSpecialInstruction" ErrorMessage="Special instruction can't exceed 200 characters"
                                    ValidationExpression="^[\s\S]{0,200}$" runat="server" Display="None"  SetFocusOnError="true" />

    Sunday, October 30, 2011 11:01 PM