Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

98
Visualizações
TFN validation code with rendering parts not working - ReactJS

So I need to make a straight Reactjs TFN validator and because I'm very new to Javascript, I'm having a lot of trouble. I've tried countless fixes but none have worked with the integration standards that I need to abide by. I'm sure I've just made a dumb mistake but I can't see it. If anyone wants to spend 10 minutes looking at what I've written and giving feedback, I'd really appreciate it and if someone does figure out how to get it working, I'm sure anyone else who could use this will appreciate. Thanks!

import React, {useState} from 'react'


export function TfnForm(props) {
    
    const [tfnvalue,settfnvalue] = useState("");
    const [success, setsuccess] = useState(false)
    var tfnconf = false;
    var sum = 0;
    console.log(tfnconf,"initiate")


    const handleValidation = validate => {
        setsuccess(current => !current)
    }


///return statements for render
    var doSuccess = function(message) {
        
        ('#result').addClass('bg-success').text(message).show();
    };
    var doError = function(message) {
        
        ('#result').addClass('bg-danger').text(message).show();
    };

///validation algorithm
    const validate = () => {
        
        if (tfnvalue.length === 9);
            sum = (tfnvalue[0]*1)
                    + (tfnvalue[1]*4)
                    + (tfnvalue[2]*3)
                    + (tfnvalue[3]*7)
                    + (tfnvalue[4]*5)
                    + (tfnvalue[5]*8)
                    + (tfnvalue[6]*6)
                    + (tfnvalue[7]*9)
                    + (tfnvalue[8]*10);
            sum = sum%11
            if (sum === 0) {
                return (
                    doSuccess("Valid Tax File Number")
                )
            }
            return (
                doError("Invalid TFN, check the digits.")
                )
            }
            
        
    
///rendering html
    return (
        
        <div className="container">
            <form id="tfn_validator">
                <h2>TFN Validator</h2>
                    <div className={success ? 'has-success':'has-error'}>
                        <label htmlFor="tfn" className="sr-only">TFN</label>
                        <input type="text" id="tfn" size="40" className="form-control input-lg" placeholder="Enter the TFN" autoComplete="off" onChange={v=>settfnvalue(v.currentTarget.value)} required autoFocus />
                 </div>
                    <br />
                <button className="btn btn-lg btn-primary btn-block" type="button" onClick={validate}>Validate</button>
                <br />
                
            </form>
            <br />
        </div>
    )}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda