Better invalid character handler

Handles invalid numbers set as first and last numbers better.