Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6715235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:35:25+00:00 2026-05-26T08:35:25+00:00

So I know it would be easier to just use the php is_numeric function,

  • 0

So I know it would be easier to just use the php is_numeric function, but what i’m trying to do is create a regular expression, mostly for learning regex, to test test scores. The range can be 0-100, but can have 2 decimal places. This is what I have so far and its not working.

  if (preg_match("^([0-9]){2,3})(.[0-9]{2})?$([0-9]{1})?$", $quiz1))
    {
        echo "match";
    }
    else {
        $error = true;
    }

If I’m thinking correctly the literal meaning:

start of string find characters 0-9, for two places.
optional end of string decimal and find characters 0-9, for two places.
optional end of string find characters 0-9, for 1 place.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:35:26+00:00Added an answer on May 26, 2026 at 8:35 am

    Why not something like this?

     /^(?:100|\d{1,2})(?:\.\d{1,2})?$/
    
    • ^ – beginning of string
    • (?:100|\d{1,2}) – non-capturing group, 100 or 0-99
    • (?:.\d{1,2})? – optional non-capturing group (.# or .##)
    • $ – end of string

    Results:

    php > $tests = array(0, 5, 10, 50, 100, 99.5, 75.43, 75.436, 101);

    php > foreach ($tests as $test) { print $test . ” – ” . preg_match(“/^(?:100|\d{1,2})(?:\.\d{1,2})?$/”, $test) . “\n”; }

    0 – 1

    5 – 1

    10 – 1

    50 – 1

    100 – 1

    99.5 – 1

    75.43 – 1

    75.436 – 0

    101 – 0

    75F43 – 0

    Yours doesn’t work even when I add the slashes and remove the extra ).

    php > foreach ($tests as $test) { print $test . ” – ” .
    preg_match(“/^([0-9]{2,3})(.[0-9]{2})?$([0-9]{1})?$/”, $test) . “\n”; }
    0 – 0

    5 – 0

    10 – 1

    50 – 1

    100 – 1

    99.5 – 0

    75.43 – 1

    75.436 – 0

    101 – 1

    75F43 – 1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this would be easy with position:fixed, but unfortanately I'm stuck with supporting
I'm trying to determine the window position of an application. I know SetWindowPos() would
I am trying to create a go-moku game using jquery,php, and mysql database. I
I would like to know what would be the best way to do unit
I would like to know what would be the impact of modifying web.config file
Does anyone know what would be the minimum rights I would need to grant
As most of you would know, if I drop a file named app_offline.htm in
Thinking in regards to Sliverlight, I would like to know where would be good
i would to know how to write a profiler? What books and / or
How would I know the maximum number of messages a JMS Queue can hold?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.