Pattern Matches for Decimal and Zero Value - InfoPath Dev
in

InfoPath Dev

Pattern Matches for Decimal and Zero Value

Last post 04-19-2016 07:54 AM by Hilary Stoupa. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 04-15-2016 12:35 PM

    Pattern Matches for Decimal and Zero Value

    Hi, I'm trying a pattern match on a decimal data type. Right now I have the results that I want (any positive or negative decimal number is valid), except that it won't match 0 (zero), which should be valid.  Here is my expression:

    -?\d*?\.\d*

    The text box containing the decimal (default value is 0.000) is formatted as a percentage with 3 decimal places. So 0 appears as 0.000. Is this what's throwing off my expression to find 0 (or 0.000) invalid?  I have a work around where my rule to has the following condition:

     field matches custom pattern (-?\d*?\.\d*) or field = 0

     This works, but  I really want to know why the expression itself isn't working. Everything I've found online says it should. (I also tried -?\d*\.\d*) and it didn't work. I don't have a lot of experience with these, so I may have some obvious issue that I'm not seeing.

    Thanks! Gwen 

     

    Filed under: ,
  • 04-18-2016 05:29 AM In reply to

    Re: Pattern Matches for Decimal and Zero Value

    Hi Gwen,

    My first guess is that pattern matching validation only works on strings.

    Can you add a separate string field for your input and set the decimal field when it changes (assuming it matches the value)?

    My second guess is that it is getting hung up on the '\.' since the dot has special parsing meaning. But, your slash prefix should take care of that.

    You can control the number of items by affixing \d{0,3} which will match a number 0 or 1 or 2 or 3 times but not 4 or more.

    Hope this helps in some way.  

    Patrick Halstead
    Project Manager at Qdabra
  • 04-18-2016 07:03 AM In reply to

    Re: Pattern Matches for Decimal and Zero Value

    Thanks, Patrick! I'll give that a try. 

  • 04-19-2016 07:39 AM In reply to

    Re: Pattern Matches for Decimal and Zero Value

    For reference on pattern matching with decimals (in case anyone is looking for this)... I ended up using a string field with the following pattern match:

     \-?\d+\.?\d{0,3}

    This allows any negative or non-negative whole number or decimal (up to 3 places).

     Originally I tried   \-?\d*\.?\d{0,3} but this allowed a negative sign to be a valid value (no numbers) because the * means any number of digits (including zero).

     

  • 04-19-2016 07:54 AM In reply to

    Re: Pattern Matches for Decimal and Zero Value

    Thanks for updating with your final working solution, Gwen! :)
    Hilary Stoupa

Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.