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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:45:47+00:00 2026-06-11T11:45:47+00:00

I am using a javascript to validate input from a textbox that’s inside a

  • 0

I am using a javascript to validate input from a textbox that’s inside a ASPxGridView control(DevExpress component).

I am using this javascript code to validate it(thru OnKeyPress event):

function CheckKey(s, e) {
    var key = ASPxClientUtils.GetKeyCode(e.htmlEvent);
    var char = String.fromCharCode(key);
    if (e.htmlEvent.shiftKey) {
        if (!IsAvailableChar(char))
            ASPxClientUtils.PreventEvent(e.htmlEvent);
    } else
        if (!(IsAvailableChar(char) || IsAvailableKey(key))) ASPxClientUtils.PreventEvent(e.htmlEvent);

    return;
}

function IsAvailableChar(char) {
    var AvailableChars = "0123456789,";
    return AvailableChars.indexOf(char) != -1;
}

function IsAvailableKey(key) {

    switch (key) {
        case 46: //delete
            return true;
            break;
        case 37: //left arrow
            return true;
            break;
        case 39: //right arrow
            return true;
            break;
        case 16: //shift
            return true;
            break;
        case 188: //comma
            return true;
            break;
        default:
            return false;
            break;
    }

I use this to “block” some characters and it works fine.
But now I wanna do something a little bit more complicated: I don’t want the user to input more than one comma in the textbox.

A little bit more complicated than that: the maxlength of this textbox is 6. I want it to allow two decimal places only and the maximum of three numbers before the decimal places.
For example:
I want it to allow these strings: “123,12”, “45,32”, “7,65”, “9,6”, “85,32”, “94,1”, “310,2”.
I don’t want it to allow these strings: “1,123”, “125,789”, “1234,2”

Any ideas on how I can do that?

Thank you!

Edit:

I tried to use the two regular expressions you guys told me to like this:

function CheckKey(s, e) {
    var key = ASPxClientUtils.GetKeyCode(e.htmlEvent);
    var char = String.fromCharCode(key);

    var text = document.getElementsByName(s.uniqueID)[0].value + char;

    var regEx = new RegExp("/^\d{0,3}(,\d{0,2})?$/");

    if(regEx.test(text))
        return;
    else
        ASPxClientUtils.PreventEvent(e.htmlEvent);

    return;
}

However, regEx.test(text) is always returning false, even when the input matches the regular expression.

Another edit:

I changed the instantiation of the RegExp object in the code above from this:

var regEx = new RegExp("/^\d{0,3}(,\d{0,2})?$/");

To this:

var regEx = /^\d{0,3}(,\d{0,2})?$/

And now it worked, thank you!

  • 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-11T11:45:49+00:00Added an answer on June 11, 2026 at 11:45 am
    /^\d{0,3}(,\d{0,2})?$/.test(textbox.value + char);
    

    This will match any number with as many as three pre-decimal places. Optionally, it allows a decimal and up to 2 decimal places. Also matches the empty string, for ease of use. So this will check to make sure the resultant box matches.

    An explanation of the regEx:

    ^
    

    Start of string

    \d{0,3}
    

    0 to 3 digits (inclusive)

    (...)? 
    

    An optional group

    ,\d{0,2}
    

    A comma followed by 0 to 2 digits (inclusive)

    $
    

    End of string.

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

Sidebar

Related Questions

I need to validate my textbox using JavaScript, so far i made this :
I am using javascript to validate user input on my aspx page. I am
im creating a website and im using javascript to validate information this is the
I am trying to validate email using javascript but for some reason it is
I am trying to validate an e-mail address using javascript. The problem is the
I'm using the following regexp to validate numbers in my javascript file: var valid
Using JavaScript I open the pop window and parent window is inactive at this
using Javascript, it is easy to programatically select the text inside a textarea or
I'm using jquery.validate plugin and facing the following situation: <form id=myForm ....> <input type=text
From this previous post I have this code: @model SuburbanCustPortal.Models.AddCustomerModel @{ ViewBag.Title = Add

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.