Added error handling to isValidNumber: method