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

89
Views
Reactjs IsNaN not validating inputs correctly

I have a readOnly input that calculates a value based on two other inputs (qty and price). In the getLineTotal() function, I am trying to validate the inputs and am having an issue when the input receives a blank value.

const getLineTotal = (e: any): void => {
        let parsedPrice: number;
        console.log(typeof e.target.value)
        if(Number.isNaN(e.target.value)){
            console.log("yes")
            parsedPrice = 0;
        }
        else{
            parsedPrice = parseInt(e.target.value);
        }
        setPrice(parsedPrice);
        console.log(qty, parsedPrice, "=>", qty * parsedPrice)
        setTotal(qty * parsedPrice);
    }

I have tried multiple different methods of detecting this NaN value, but nothing has worked. The console says it's a string but then says received NaN for value attribute.

string
LineDetail.tsx:38 12 12 '=>' 144
LineDetail.tsx:29 string
LineDetail.tsx:38 12 NaN '=>' NaN

Any ideas?

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!