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

246
Views
How to validate cheque number in Java Script

Generally (in India) there are six digits in a cheque number (If some bank has different number pattern then I don't know). I don't know whether any other restriction on digits or not, like the first digit may be 'zero' or not. Which regEx or other method, I should use to verify that the cheque number entered in HTML form is valid or not. I don't know regEx well. It doesn't give false for a cheque number starting from 0.

I might go with one of the following, but which is the best ?

var chequeNos1 =  ['111101', '222212', '234330', '044400'];
var chequeNos2 =  ['111101', '222212', '234330', '444400'];
var chequeNos3 =  ['111101', '222212', '234330', '44400'];
console.log(validateChequeNumbers(chequeNos1))
console.log(validateChequeNumbersByRegEx(chequeNos1))
console.log(validateChequeNumbers(chequeNos2))
console.log(validateChequeNumbersByRegEx(chequeNos2))
console.log(validateChequeNumbers(chequeNos3))
console.log(validateChequeNumbersByRegEx(chequeNos3))


function validateChequeNumbers(chequeNos){
  var areAllChequeNosValid = chequeNos.every(chequeNo =>{
    // console.log(100000 <= parseInt(chequeNo) && parseInt(chequeNo) <= 999999);
    return 100000 <= parseInt(chequeNo) && parseInt(chequeNo) <= 999999;
  })
  return areAllChequeNosValid;
}

function validateChequeNumbersByRegEx(chequeNos){
  var areAllChequeNosValid = chequeNos.every(chequeNo =>{
    var validateReg = /^\d{6}$/;
    // console.log(chequeNo.match(validateReg));
    if(chequeNo.match(validateReg)){
      return true;
    }else{
      return false;
    }
  })
  return areAllChequeNosValid;
}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I'd encourage you to use the regex approach and also to factor out the validation test from the document parsing. That way you can create unit tests that check the validation logic independently.

Something like:

const chequeNumbers = [
  '012345',
  '123456',
  '234567',
  '345678'
];
const chequeNumberRE = /^\d{6}$/;

const validateChequeNumbers = checkNumbers => (
    chequeNumbers.every(chequeNumber => chequeNumberRE.test(chequeNumber))
)

validateChequeNumbers(chequeNumbers)

Then call your function something like, validateChequeNumbersFromDocument or suchlike.

Please note: Indian cheque numbers may begin with any digit, not just zero.

about 4 years ago · Juan Pablo Isaza Report
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!