Web Analytics Made Easy -
StatCounter RegExp problem in validating a form - CodingForum

Announcement

Collapse
No announcement yet.

RegExp problem in validating a form

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • RegExp problem in validating a form

    Hi.

    I'm using a Regular Expression to validate fields in a web form. Here's the expression:

    /^[0-9]+([0-9]{3})*$/;

    Using this expression in my JavaScript validation, I can prevent users from entering anything but whole, positive numbers.

    What I would like to do is also allow NEGATIVE numbers. How can I modify the expression to do this? I gotta get this done QUICK, so any help is greatly appreciated. I'm really bad at RegExp stuff...

    Thanks!

    Sam
    Last edited by SamSteinig; Aug 1, 2005, 10:38 AM.

  • #2
    Im no good with regexp but couldnt you just allow a "-".
    <JPM />

    Comment


    • #3
      Yes, but where exactly in the expression would I insert the "-"??

      Comment


      • #4
        This should do it for you:

        /^[-]?[0-9]+([0-9]{3})*$/
        ScriptingMagic.com

        Comment


        • #5
          Actually, you should simplify to this:
          /^[-]?[0-9]+$/
          Unless you're trying to capture the ending groups of three.
          ScriptingMagic.com

          Comment


          • #6
            It works!

            Thanks a bunch!!

            Sam

            Comment

            Working...
            X