alphanum (v2)

Revision 2 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
if
const CHARS = new Set("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
function isAlphanumeric(char) {
    return CHARS.has(char);
}


isAlphanumeric("thisisalongstring8989IDONNTKNOW")
isAlphanumeric("aze123AZE")
isAlphanumeric("aze*ZE")
isAlphanumeric("azdsdsjdksjkdjlefjusqfi--ZE")
ready
loop
function isAlphaNumeric(str) {
  var code, i, len;

  for (i = 0, len = str.length; i < len; i++) {
    code = str.charCodeAt(i);
    if (!(code > 47 && code < 58) && // numeric (0-9)
        !(code > 64 && code < 91) && // upper alpha (A-Z)
        !(code > 96 && code < 123)) { // lower alpha (a-z)
      return false;
    }
  }
  return true;
};

isAlphaNumeric("thisisalongstring8989IDONNTKNOW")
isAlphaNumeric("aze123AZE")
isAlphaNumeric("aze*ZE")
isAlphaNumeric("azdsdsjdksjkdjlefjusqfi--ZE")
ready
regex
const ALPHA_NUMERIC_PATTERN = '/^[a-z0-9]+$/i';
ALPHA_NUMERIC_PATTERN.test("thisisalongstring8989IDONNTKNOW");
ALPHA_NUMERIC_PATTERN.test("aze123AZE");
ALPHA_NUMERIC_PATTERN.test("aze*ZE");
ALPHA_NUMERIC_PATTERN.test("azdsdsjdksjkdjlefjusqfi--ZE");
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.