Re: validate that string input is a negative number

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Mar 28, 7:47 am, "Mythran" <kip_pot...@xxxxxxxxxxx> wrote:
"Alberto Poblacion" <earthling-quitaestoparacontes...@xxxxxxxxxxxxx> wrote
in messagenews:uAO52jUcHHA.4888@xxxxxxxxxxxxxxxxxxxxxxx

"Larry Lard" <larryl...@xxxxxxxxxxxxxx> wrote in message
news:56vca3F29fvh4U1@xxxxxxxxxxxxxxxxxxxxx
- Use a regular expression such as "-\d+".

Also, that regular expression would pass "-0", which isn't negative.

Okay, let's refine it a little:

@"^-[1-9]\d*$"

lol sorry, have too:

-01 wouldn't pass the above expression pattern...

@"^-\d*[1-9]\d*$" should...haven't tested though...

Or just a nice simple
int val;
return Int32.TryParse(s, out val) && val < 0

Michael


.