Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
How to get only 9 Digits before decimal and 2 digits after in a text box which only contains Decimal Value?

The below function I have created takes input in decimal only and maximum 12 char are allowed in it but it failed in 1 case where if user enters for example 12.45 and he/she again puts the cursor behind the decimal and start typing, it doesn't let the user enter though the capacity is 9 char before decimal and 2 after the decimal.

The Function is called on the keypress event.

Any help is appreciated Thanks!!

function isDecimalNumberWithOnlyNumbersandScaleTwoFunc(event) {

if (!event)
    event = window.event;
var charCode = (event.which) ? event.which : event.keyCode;
var elementValue = event.target.value;
if (event.key == "." && elementValue.indexOf('.') != -1) {
    event.preventDefault();
    return false;
}

if ((event.key == "." || isNumberKey(event))) {
    if ((event.key == "." || isNumberKey(event)) && (elementValue.substring(elementValue.indexOf('.'), elementValue.length).length <= 2)) {
        return true;
    }
    else if (isNumberKey(event)) {
        if ((elementValue.indexOf('.') != -1)) {
            event.preventDefault();
            return false;
        }
        else if (elementValue.length < 9) {
            if (isNumberKey(event) || event.key.toLowerCase() == "del" || event.key.toLowerCase() == "delete" || charCode == 46) {
                return true;
            }
            else
                return false;
        }
    }
    else if (event.key == ".") {
        return true;
    }
    event.preventDefault();
    return false;
}
else
    return false;

}

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!