Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sean Parsons 23 posts 38 karma points
    Sep 27, 2009 @ 17:27
    Sean Parsons
    0

    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

  • Masood Afzal 176 posts 522 karma points
    Sep 27, 2009 @ 17:31
    Masood Afzal
    1

    Integer:   [0-9]*
    Double:   [0-9][\.0-9]*

  • Sean Parsons 23 posts 38 karma points
    Sep 27, 2009 @ 21:32
    Sean Parsons
    0

    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...

  • Sean Parsons 23 posts 38 karma points
    Sep 27, 2009 @ 21:35
    Sean Parsons
    0

    Oh - and how would you limit it to 2 decimal places?

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Sep 28, 2009 @ 06:11
    Richard Soeteman
    0

    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

  • Sean Parsons 23 posts 38 karma points
    Sep 28, 2009 @ 22:15
    Sean Parsons
    0

    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?

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Sep 30, 2009 @ 11:01
    Richard Soeteman
    0

    Hi Sean,

    I assume that teh underlying datatype is a string instead of number?

    Cheers,

    Richard

  • Petr Snobelt 923 posts 1535 karma points
    Sep 30, 2009 @ 12:58
    Petr Snobelt
    0

    @richard: It must be string, numeric datatype dosn't allow decimal separator

  • Sean Parsons 23 posts 38 karma points
    Sep 30, 2009 @ 22:05
    Sean Parsons
    0

    Man oh man. It's always the simplest of things, isn't it?? Thanks Richard and Petr.

Please Sign in or register to post replies

Write your reply to:

Draft