Results 1 to 2 of 2

Thread: How to count maximum values inside text box?

  1. #1
    Join Date
    Sep 2005

    How to count maximum values inside text box?

    I like to count number of characters inside text box.
    1. How to do it with PHP to echo it or/and
    2. limit it to maximum with warning and/or
    3. how to set it with automatic Javascript code when user filled text box?

    Need help.

  2. #2
    Join Date
    Oct 2010
    Versailles, France
    In my opinion, the best solution consists in using regular expressions...
    With javascript, the single following lines count characters (we remove all other characters before).
    // For lower or upper case letters  
    var result=str.replace(/[^a-z]+/gim,'').length;
    // For lower word characters depending of the local setting  
    var result=str.replace(/[\W]+/gim,'').length;
    // For lower word or digits characters  
    var result=str.replace(/[\W\D]+/gim,'').length;
    It is the same thing with PHP
    PHP Code:
    $result=strlen($str);// Or mb_strlen($str); with character encoding 
    Last edited by 007Julien; 12-15-2011 at 08:21 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center