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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:21:30+00:00 2026-05-25T11:21:30+00:00

How would I validate the precision/scale of a number posted from a form to

  • 0

How would I validate the precision/scale of a number posted from a form to make sure it can be stored in an Oracle NUMBER column? For example:

<input type="number" name="foo" value="123.45" />

The user submits the form to the PHP backend…

<?php
function isValidNumber($number, $precision, $scale) {
    // ???

    return $isValid;
}

// The precision and scale here are actually dynamic
$isValid = isValidNumber($_POST['foo'], 5, 2);

…where I would like to be able to validate the number without trying to insert/update it in Oracle and handle any precision overflow errors (proactive design, rather than reactive). I have not been able to come up with a method of accurately validating all the various fringe cases (Oracle doesn’t produce errors for scale overflow – it just rounds to the maximum, but this rounding could lead to precision overflows, which do produce errors, etc.).

  • 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-25T11:21:30+00:00Added an answer on May 25, 2026 at 11:21 am
    function isValidNumber($number, $precision, $scale) {
        $isValid = false;
        if (is_numeric($number)) {
            $num = round(abs($number), $scale);
            $max = str_repeat('9',$precision - $scale).'.'.str_repeat('9',$scale);
            $isValid = $num <= $max;
        }
        return $isValid;
    }
    

    Output for isValidNumber($number, 5, 2)

    123.456   (valid)
    9999.999  (invalid)
    99999.999 (invalid)
    12.003    (valid)
    999.99    (valid)
    999.999   (invalid)
    1234.5    (invalid)
    

    and finally

    isValid(1234567890123456789012345678.90, 30, 2) == **valid**

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

Sidebar

Related Questions

How would I validate the Third Step on my multi-stage jQuery form? It can
I would like to validate a form so that it checks if the user
I would like to validate the DNF (Disjunctive normal form) which looks like this
I would like to validate IP addresses from a list that may contain incorrectly
How would I validate with Javascript/jQuery that a phone number matches the format of
I'd like to know if I can write a validation that would validate the
I would like to validate both single field and multiple field data from a
I would like to validate an input from a textbox so that it is
I would like validate the current date with question posted date if date difference
How would I validate hidden inputs and not visible text inputs with jQuery Form

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.