Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8109215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:20:56+00:00 2026-06-06T01:20:56+00:00

I want to get the string length when a key is pressed like StackOverflow

  • 0

I want to get the string length when a key is pressed like StackOverflow does.

Example of StackOverflow showing length

I have tried to do this with onblur, but it’s not working. How do I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:20:58+00:00Added an answer on June 6, 2026 at 1:20 am

    As for the question which event you should use for this: use the input event, and fall back to keyup/keydown in older browsers.

    Here’s an example, DOM0-style:

    someElement.oninput = function() {
      this.onkeydown = null;
      // Your code goes here
    };
    someElement.onkeydown = function() {
      // Your code goes here
    };
    

    The other question is how to count the number of characters in the string. Depending on your definition of “character”, all answers posted so far are incorrect. The string.length answer is only reliable when you’re certain that only BMP Unicode symbols will be entered. For example, 'a'.length == 1, as you’d expect.

    However, for supplementary (non-BMP) symbols, things are a bit different. For example, ''.length == 2, even though there’s only one Unicode symbol there. This is because JavaScript exposes UCS-2 code units as “characters”.

    Luckily, it’s still possible to count the number of Unicode symbols in a JavaScript string through some hackery. You could use Punycode.js’s utility functions to convert between UCS-2 strings and Unicode code points for this:

    // `String.length` replacement that only counts full Unicode characters
    punycode.ucs2.decode('a').length; // 1
    punycode.ucs2.decode('').length; // 1 (note that `''.length == 2`!)
    

    P.S. I just noticed the counter script that Stack Overflow uses gets this wrong. Try entering , and you’ll see that it (incorrectly) counts as two characters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a String in Java called Kiran<kiran@gmail.com> . I want to get String
i have a string like this: blablablamorecontentblablabla?name=michel&score=5&age=28&iliedabouttheage=true looks like a regular query string yes,
I want to encrypt a string using AES with my own key. But I'm
From several classes in my app I want to get String global values without
I want to get a string contained within a string where every time I
dim dataType as String toolTip=Marks And Number[String] I want to get the [String] alone.
I'm writing an Apache module and want to get a string with the Apache
I want to get the input String splitted by a colon. For example, a:int
I want to get the part of the string before the last occurance of
I want to get some value from a string. For example: String string= Name:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.