if vs else (v4)

Revision 4 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
regex
function validate(str) {
  if(str.length > 25) return false;
  return /^[A-Za-z0-9\ \-]+$/.test(str)
};
validate("AASDFWEradsgadfg -6")
ready
non-regex
function validate(str) {
  let char = "";
  let len = str.length
  if(len > 25) return false;
  for (let i = 0; i < len; i++) {
    char = str[i];
    if ((char >= "0" && char <= "9") || // numeric (0-9)
        (char >= "A" && char <= "Z") || // upper alpha (A-Z)
        (char >= "a" && char <= "z") || // lower alpha (a-z)
        (char == " " || char == "-")){ // special chars
    }else{
    	return false;
    }
  }
  return true;
};
validate("AASDFWEradsgadfg -6")
ready

Revisions

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