Safe parser for port value