Javascript function for validating numbers