2 Replies Latest reply on Apr 14, 2010 8:40 AM by marcel.m.vielsack.cluetec.de

    Crashcourse Regex

    marcel.m.vielsack.cluetec.de

      Hi!


      I'm validating an input with the @Pattern annotation and want my regex to match patterns like this:


      1.0, 1, 1.25, 12.45


      and I built this regex:


      (^[0-9]+.?[0-9]*$)


      But the validation fails ... :(


      Does anybody know why the validation fails?


      Cheers Marcel



        • 1. Re: Crashcourse Regex
          swd847
          try:


          \d+(\.\d+)?


          \d+ : matches one or more digits
          the brackets with the question mark make the decimal point part optional
          \. matches a . ( just a . matches any character)


          • 2. Re: Crashcourse Regex
            marcel.m.vielsack.cluetec.de

            Thanks for the answer, Stuart!


            I tried the regex you suggested, but seam still tells me that the regex does not match.
            I also tried a simpler regex ("\d*") and typed only integer values in my inputfield.


            in my source file it looks like this;



              @Pattern(regex = "\\d*")
              @Range(min = 0)
              private Double amount;



            Is there maybe a problem because I'm trying to validate a Double with a regex?