I’m wondering how to implement strict parsing of a string in C#.
Specifically, I want to require that the string contains just the number (in culture-specific format), and no other characters.
"1.0" -> 1.0
"1.5 " -> fail
" 1.5" -> fail
" 1,5" -> fail (if culture is with ".")
"1,5" -> fail
Cheers!
The
Int32.Parsemethod accepts flags covering certain situations you mention. Have look into MSDN here onNumberStylesenumeration. Also, it accepts culture-specific formatting information.