Coldfusion textarea - maxlength validation

Posted on 2009-02-19
Last Modified: 2013-12-20
Hello experts.
I need a help with validating (serversite) a textarea where i want to allow maximal 1000 characters.
Here is my code:
<cfif Form.mytexarea NEQ "">
Question by:Panos
    LVL 16

    Accepted Solution

    <cfif Len(Form.mytextarea) GT 1000>
    <!--- it's too long --->

    LVL 19

    Expert Comment

    it can be done by JS.
    function charAlert(textField)
          if(textField.value.length > 1000)
                /* must be > 1000, not == 1000 or else the substring statement on the next line will cause the function to run again if the user dismisses the alert by pressing the 'enter' key rather than clicking 'OK'. */
                textField.value= textField.value.substring(0,1000)
                // set field's value equal to first five characters.
                /* move cursor out of form element to keep it from placing itself at position zero, causing an overwrite of the first character */
                alert("You reached the maximum number of characters allowed");
    then you apply this to the textarea
    as onblur="charAlert (document.formname.textAreaname)"
    LVL 2

    Author Comment

    Hi duncancumming:
    Your code is working
    Hi erikTsomik.
    Thank you for your help too but  i was asking for a server side validation.
    LVL 2

    Author Closing Comment

    Thank you again for your help

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
    When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
    The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
    The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now