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
2010-10-04 20:23:51
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
2010-10-06 19:59:53