Guard against malicious string inputs for numbers. Closes #1903.