I'm trying to validate double with regular expressions in data annotations.
I need a regex that validates as it follows:
Pass:
- 1,00
- 0,01
- 0,00
- 123544,23
- 266,00
Always 2 decimals.
Fails:
- ,22
- 0,
- ,00
- 1,0
- 1,2
So far I've got
^\d+,\d{2}$
But it fails when the numbers ends in zero. For example, 23,00 fails when it should pass.
Note: I use comma as separator because of my culture.
EDIT: I'm using globalization for jQuery Validate. In the view I have this script.
$(document).ready(function () {
Globalize.culture('es-AR');
$.validator.methods.number = function (value, element) {
return this.optional(element) || !isNaN(Globalize.parseFloat(value));
}
$.validator.methods.range = function (value, element, param) {
return this.optional(element) || (Globalize.parseFloat(value) >= param[0] && Globalize.parseFloat(value) <= param[1]);
}
});