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 7505029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:46:26+00:00 2026-05-29T21:46:26+00:00

There is a textbox in the form, in which only specific number inputs are

  • 0

There is a textbox in the form, in which only specific number inputs are allowed. i.e

0.5, 1, 1.5, 2, 2.5, 3........ and so on

How can i mask this textbox for these inputs? Or what regex should i use?

  • 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-29T21:46:28+00:00Added an answer on May 29, 2026 at 9:46 pm

    If you only want to validate on submit, you can simply use parseFloat, Math.floor and toString:

    function isValidValue(text) {
        return text == (Math.floor(parseFloat(text) * 2) / 2).toString();
    }
    

    Or you can perform a regex check with string replace, .replace(/[^0-9\.]/g, ""). That only allows numbers and periods/decimal points. Unfortunately, it does not prevent multiple decimal points.

    If you want to restrict actual keystrokes, you need something more. Attach the following function to the keyup event for your textbox. Remember to use return isValidKey(this, event) instead of simply isValidKey(this, event):

    function isValidKey(me, evt) {
    
        var charCode = (evt.which) ? evt.which : event.keyCode;
        var currValue = me.value;
    
        // disallow decimal point if it is not the first one
        if ((charCode == 46 || charCode == 110 || charCode == 190) && currValue.indexOf(".") != -1)
            return false;
    
        // disallow non numeric characters
        if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
    
        return true;
    }
    

    ​

    http://jsfiddle.net/SHJsz/

    Update: It is now slightly more strict, but still not foolproof. You can still have a number with a leading 0 or start with a decimal point if the user uses backspace or delete to remove the original starting numbers.

    http://jsfiddle.net/SHJsz/1/

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

Sidebar

Related Questions

Im designing a dialerPad form using Windows form, there is a textbox which should
In .Net, there is the MaskedTextBox and there is the TextBox which has an
Is there anyway in XAML only to have a linebreak in a TextBox? I
Is there a way to get an ASP.NET textbox to accept only currency values,
I want to let TextBox control TextChanged event fire only when there are more
I'm trying to single source a form page which can be in edit mode
Hey all, I have an HTML form on my website which currently only uses
i have a form, which hosts a tabcontrol. each of these tabs have plenty
Is there a way to create a ScrollViewer which only allows content to scroll
I am having a form in which I can input data from one window

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.