refactor to cast to Integer and rescue ArgumentError instead of using regexp