title: What is wrong in the below code of input validation?
body: <p>I have trying to validate an input text field, which should contain only characters. I am using test() here. Ideally it should return true when the field is given string like &quot;rent&quot; but in every case it is going for the false scenario. Can someone please suggest why it is happening. I have tried debugging and found out that the values are coming fine in if statement. Please help.</p>
  <pre><code>    const [text,setText] = useState(&quot; &quot;)
      const [amount,setAmount] = useState(0)
    
      const {addTransaction} = useContext(GlobalContext)
      console.log(text,amount)
  
  
     const onSubmit = e =&gt;{
     e.preventDefault(); 
     var letters = /^[A-Za-z]+$/;
    
     if(letters.test(text)){
     const newTransantion = {
     id: Math.floor(Math.random() * 10000000),
     text:text,
     amount:+amount
     } 
     addTransaction(newTransantion)
    }
    else{
      alert('Please give the correct input')
    }
  }
  </code></pre>