I need to add validation for basic decimal entry (eg. a price field)
The regular expression I am trying to use is:
^(\d+((\.\d{1,2}){1})?)$
This is valid (tested with The Regulator tool, if anyone knows that one) but anything other than an integer gets rejected by Umbraco validation with that expression. (I've tried it with and without the ^ and $)
If you use a Regular expression it comes from regxeplib.com. The site has a nice tester so you could use the regular expression of choise that you find there and tweak it for your own needs.
Decimal Validation in Doc Type Properties
Hi all,
I need to add validation for basic decimal entry (eg. a price field)
The regular expression I am trying to use is:
^(\d+((\.\d{1,2}){1})?)$
This is valid (tested with The Regulator tool, if anyone knows that one) but anything other than an integer gets rejected by Umbraco validation with that expression. (I've tried it with and without the ^ and $)
Thanks,
Sean
Integer: [0-9]*
Double: [0-9][\.0-9]*
Thanks - simpler... However, any idea why the original (and also valid) regex doesn't work in Umbraco?
I'd like to find out why, in case I have a need for more complex regexes and I come up against this again...
Oh - and how would you limit it to 2 decimal places?
HI Sean,
If you use a Regular expression it comes from regxeplib.com. The site has a nice tester so you could use the regular expression of choise that you find there and tweak it for your own needs.
Cheers,
Richard
I have tried that regex tester on that site for ^(\d+(\.\d{1,2})?)$ and it gives me the results I expect.
However, I still cannot get this to work in Umbraco. Any other ideas out there?
I'm a bit concerned, as this isn't a particularly complex regex - but Umbraco blanks out the value and raises a validation error.
Perhaps some characters need to be escaped?
Hi Sean,
I assume that teh underlying datatype is a string instead of number?
Cheers,
Richard
@richard: It must be string, numeric datatype dosn't allow decimal separator
Man oh man. It's always the simplest of things, isn't it?? Thanks Richard and Petr.
is working on a reply...