hash = window.location.hash.substr(1);
var reg = new RegExp('^[0-9]$');
console.log(reg.test(hash));
I get false on both "123"
and "123f"
. I would like to check if the hash only contains numbers. Did I miss something?
var reg = /^\d+$/;
should do it. The original matches anything that consists of exactly one digit.