Skip to content

Instantly share code, notes, and snippets.

@DanielHemmati
Created July 22, 2022 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanielHemmati/6cdf1bcc9e4c18fb24822d2a4521b1a0 to your computer and use it in GitHub Desktop.
Save DanielHemmati/6cdf1bcc9e4c18fb24822d2a4521b1a0 to your computer and use it in GitHub Desktop.
check if the char is alphanumeric
// source: https://stackoverflow.com/questions/4434076/best-way-to-alphanumeric-check-in-javascript
// i just edited a little bit
/**
*
* @param {string} char
* @returns
*/
function isAlphaNumeric(char) {
let code = char.charCodeAt(0);
if (
!(code > 47 && code < 58) && // numeric (0—9)
!(code > 64 && code < 91) && // upper alpha (A—Z)
!(code > 96 && code < 123) // lower alphaa (a-a)
) {
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment