RegExp

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Enzo

    RegExp

    Hi,

    I need to create a dynamically pattern match
    for validate a number input, first without
    decimals and then with 2 or more decimals.

    Thanks in advance,

    Enzo


  • Evertjan.

    #2
    Re: RegExp

    Enzo wrote on 30 aug 2005 in comp.lang.javas cript:
    [color=blue]
    > I need to create a dynamically pattern match
    > for validate a number input, first without
    > decimals and then with 2 or more decimals.[/color]

    What do you mean by "dynamicall y"?

    What did you try yourself?


    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)

    Comment

    • Enzo

      #3
      Re: RegExp

      Hi Evertjan,

      I tried this pattern:

      /^-?\d+(\.\d{1,3}) ?$/

      for 1 to 3 decimals, but I need to replace
      the static values '1' & '3' with variables.

      Thanks again,

      Enzo


      Comment

      • Evertjan.

        #4
        Re: RegExp

        Enzo wrote on 30 aug 2005 in comp.lang.javas cript:
        [color=blue]
        > Hi Evertjan,
        >
        > I tried this pattern:
        >
        > /^-?\d+(\.\d{1,3}) ?$/
        >
        > for 1 to 3 decimals, but I need to replace
        > the static values '1' & '3' with variables.[/color]

        myTestValue = 1.1234

        a = 1
        b = 3
        myRegex = "^-?\\d+\\.\\d{"+a +","+b+"}?$"
        re = new RegExp(myRegex, "");

        alert( re.test(myTestV alue) )


        --
        Evertjan.
        The Netherlands.
        (Replace all crosses with dots in my emailaddress)

        Comment

        • Alvaro G Vicario

          #5
          Re: RegExp

          *** Enzo wrote/escribió (Tue, 30 Aug 2005 11:17:10 GMT):[color=blue]
          > I need to create a dynamically pattern match
          > for validate a number input, first without
          > decimals and then with 2 or more decimals.[/color]

          You can take this a start point:

          var my_filter=new Array('foo', 'bar');
          eval('var re_filter=/^(' + my_filter.join( '|') + ')$/i;');

          --
          -- Álvaro G. Vicario - Burgos, Spain
          -- http://bits.demogracia.com - Mi sitio sobre programación web
          -- Don't e-mail me your questions, post them to the group
          --

          Comment

          • Evertjan.

            #6
            Re: RegExp

            Alvaro G Vicario wrote on 30 aug 2005 in comp.lang.javas cript:
            [color=blue]
            > *** Enzo wrote/escribió (Tue, 30 Aug 2005 11:17:10 GMT):[color=green]
            >> I need to create a dynamically pattern match
            >> for validate a number input, first without
            >> decimals and then with 2 or more decimals.[/color]
            >
            > You can take this a start point:
            >
            > var my_filter=new Array('foo', 'bar');
            > eval('var re_filter=/^(' + my_filter.join( '|') + ')$/i;');
            >[/color]

            Never use eval(),
            it is evil and not necessary.

            --
            Evertjan.
            The Netherlands.
            (Replace all crosses with dots in my emailaddress)

            Comment

            • Enzo

              #7
              Re: RegExp

              Gracias Alvaro,

              pero como dice Evertjan, eval is 'evil' ;-)

              Saludos,

              Enzo


              Comment

              • Enzo

                #8
                Re: RegExp

                Works great! Thanks Evertjan!

                Enzo


                Comment

                • Evertjan.

                  #9
                  Re: RegExp

                  Enzo wrote on 30 aug 2005 in comp.lang.javas cript:
                  [color=blue]
                  > pero como dice Evertjan, eval is 'evil' ;-)
                  >[/color]

                  Because it is true and has been explained so many times in this NG.

                  Please see the archive.


                  --
                  Evertjan.
                  The Netherlands.
                  (Replace all crosses with dots in my emailaddress)

                  Comment

                  • Dr John Stockton

                    #10
                    Re: RegExp

                    JRS: In article <1YXQe.3343174$ I96.3853437@tel enews.teleline. es>, dated
                    Tue, 30 Aug 2005 12:05:17, seen in news:comp.lang. javascript, Enzo
                    <yuyu@yuyu.co m> posted :
                    [color=blue]
                    >I tried this pattern:
                    >
                    >/^-?\d+(\.\d{1,3}) ?$/
                    >
                    >for 1 to 3 decimals, but I need to replace
                    >the static values '1' & '3' with variables.[/color]

                    Unless this is school work, you do not *need* to replace the values,
                    since you can also use (\.\d+) and test the length of the match.

                    <URL:http://www.merlyn.demo n.co.uk/js-valid.htm>

                    --
                    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                    <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
                    <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                    <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                    Comment

                    Working...