tags:

views:

100

answers:

1

Hi I need a C# regex for a positive floatin no with maximum 2 digits for decimals. Also the regex should check for letters and alphanumerical chars (not allow them) and not allow also the input value to be empty (0 characters). Thanks

+2  A: 
^[+]?[0-9]+([.][0-9]{1,2})?$

This will force it to have either a + or nothing at the start, followed by at least 1 number, then optional (decimal followed by 1 or 2 numbers)

For others, yes, I know of \d, :digit:, using \., etc. I just prefer using [0-9] and [.], it makes them stand out easier for me.

Slokun
unfortunately i have tried this with expresso it works, but when I am using a regularExpressionAttribute in C# it does not behave as expected.Basically 4.2345 passes 4. passes 4.1 does not pass.
MadalinaA