The real problem is the substring(1) function which passes the "num", instead of making sure the length is 1 it is allowing everything.