Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Posts
    151
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with reasonably simple eregi

    I have a form where users enter weight, it should be in the one of the following formats:

    72
    152.12
    65.5
    65.55
    120


    My validation eregi is as follows but doesn't seem to work:
    Code:
    if(eregi("[0-9]{1,3}[\.]{0,1}[0-9]{0,2}", $weight))
    That should equate to (1-3 numbers, followed by an optional ., followed by an optional 1-2 numbers)

    Am I missing something?

  • #2
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    Quote Originally Posted by quadrant6 View Post
    I have a form where users enter weight, it should be in the one of the following formats:

    72
    152.12
    65.5
    65.55
    120


    My validation eregi is as follows but doesn't seem to work:
    Code:
    if(eregi("[0-9]{1,3}[\.]{0,1}[0-9]{0,2}", $weight))
    That should equate to (1-3 numbers, followed by an optional ., followed by an optional 1-2 numbers)

    Am I missing something?

    That looks like it should work. What types of errors are you getting?

    Also, not sure about ereg functions (use preg_* myself) but would this work instead....

    Code:
    if(eregi("\d{1,3}\.?\d{0,2}",$weight)) {
        print "match";
    }
    else {
        print "no match";
    }

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Posts
    151
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, I would have thought so too.

    I'm not getting any errors, it's just no returning true

    The following fails (no echo):

    PHP Code:
        if(eregi("\d{1,3}\.?\d{0,2}","23")){

            echo 
    "match found";
        } 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •