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

  • SEARCH
  • Home
  • 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 8428055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:56:56+00:00 2026-06-10T04:56:56+00:00

Is there a regex or solution that tests an input field for having the

  • 0

Is there a regex or solution that tests an input field for having the following condition (as example)

I would like to test that the user input is only numbers none are decimal, greater than 0 and not greater than 20 for example. Basically I am working on client side scripting for some stuff like Quantity to add in shopping cart and I want to ensure (on client side) that he can put any values from 1 to 20, so 0 not accepted..letters, 1.3 etc…

Is there plugin or regex that tests that for me on client side?

Not sure If i got that right? Here is my attempt

    var re = /^\d+$/;
    var str = $(this).val();
    if (re.test(str) && str > 0 && str <= 20){
        status = 'success';         
    } else {
        status = 'error';
    }
  • 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-06-10T04:56:58+00:00Added an answer on June 10, 2026 at 4:56 am

    This will work:

    /^([1-9]|[1][0-9]|[2][0])$/
    

    It will match 1-20.

    Code example

    $(function() {
        "use strict";
        var limit = /^([1-9]|[1][0-9]|[2][0])$/,
            value = "19";
    
        if(limit.test(value)) {
            // Will in this example go here.
        }
        else {
            // Do something when it fails.
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there some regex that can be passed to re-seq such that it will
Is there a way to get single regex to satisfy this condition?? I am
For example I have a string like this: first:second:thirdtest:test:fourth I want to count the
Is there any solution that can compare two regular expression for Subsumption, Partially overlapping,
Given a string like Marty Mcfly is there a regex or other one line
I am parsing some HTML source. Is there a regex script to find out
There's many regex's out there to match a URL. However, I'm trying to match
I have noticed in the PHP regex library there is a choice between ereg
There is a method Regex.Replace(string source, string pattern, string replacement) The last parameter supports
Possible Duplicate: Regex to match URL Is there a regular expression to return a

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.