Created
July 22, 2022 11:13
-
-
Save DanielHemmati/6cdf1bcc9e4c18fb24822d2a4521b1a0 to your computer and use it in GitHub Desktop.
check if the char is alphanumeric
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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