c# - Regex string for validating Decimal excluding zero -


i have function creates regex string validating decimal.

public static string decimalwithplaces(int wholepart, int fractionalpart) {      return @"^-?[0-9]{0," + wholepart + @"}\.[0-9]{1," + fractionalpart + @"}$"; } 

could let me know how can excluding 0 this?

for example: "0", "0.0","0.00" etc should not matched.

thanks

amy's right - examples good.

however, i'm going in blind.

did want exclude zeros, or value of zero?

to exclude zeros, try , see happens.

public static string decimalwithplaces(int wholepart, int fractionalpart) {     return @"^-?[1-9]{0," + wholepart + @"}\.[1-9]{1," + fractionalpart + @"}$"; } 

to exclude number zero... that's not check regex. that's value check.

in books should using 2 validation steps on value. 1 check meets precision/scale requirements per regex above, second check nonzero value.

i believe using regex 0 value thing possible. advise against it. said, if you're committed ignoring reccomendation you'll want negative lookahead regex structures.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -