home ~ socials ~ projects ~ rss

Check if a Character is a Letter in JavaScript

September 2025

This is a way to check if a character is a U.S. English lower or uppercase letter via it's unicode value.

JavaScript
function isLetter(char) {
  let code = char.charCodeAt(0);
  return (code >= 65 && code <= 90) || (code >= 97 && code <= 122)
}

Here's an example:

HTML

<bitty-1-3 data-connect="CheckChar">
  <div data-receive="check">waiting</div>
  <div>
  <label>
  Character to check:
    <input data-send="check" data-receive="limit" />
  </label>
  </div>
</bitty-1-3>

Output

waiting
JavaScript
window.CheckChar = class {
  check(event, el) {
    if (event.type === "input") {
      const char = event.target.value.split("")[0];
      if (isLetter(char)) {
        el.innerHTML = `${char} is a letter`;
      } else {
        el.innerHTML = `${char} is not a letter`;
      }
      this.api.forward(event, "limit");
    }
  }

  limit(event, el) {
    el.placeholder = el.value;
    el.value = "";
  }
}
end of line

Endnotes

Unicode values 65-90 are uppercase letters A-Z.

Values 97-122 are the lowercase a-z.

You can look for characters from other languages by including their unicode values.

The opposite of .toCharCode() is String.fromCharCode()

TODO: Look up reg ex approaches to see if they handle characters with accents

Share link:
https://www.alanwsmith.com/en/33/9x/k5/1i/?check-if-a-character-is-a-letter-in-javascript