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

161
Views
pdf javascript validate field contains part of pure letter and pure numbers only

I want to check if Field1 is in the format of XXXX-0YYYY or XXXX-1YYYY where XXXX are letters only and YYYY are digits only note that after XXXX it should start with "-0" or "-1" only

I made the following code and it didn't work as expected:

var string = this.getField("Field1").value;
var string1 = string.substring(0, 4);
var string2 = string.substring(5, 10);

var n1 = event.value.indexOf("-0",4);
var n2 = event.value.indexOf("-1",4);
var n3 = n1 + n2

var isLetter = /[^a-zA-Z]/.test(string1);
var isNum = /^\d+$/.test(string2);

if ( !isLetter || n3 < -1 || !isNum ) { // incorrect format
    app.alert("ERROR MESSAGE");
    event.rc = false;
}
else {
    event.rc = true;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use a Regular Expression to achieve that, I made some tests in the RegExr website, it's a great tool to validade your regexes. I got this result:

function validateField(value) {
  return /^[A-Za-z]{4}-(0|1)\d{4}$/.test(value);
}

// Testing
console.log(['AAAA-09999', 'AAAA-19999', 'A1AA-0999Z', 'AAAA-29999', 'ZZZ-09999'].map(e => `${e} ${validateField(e) ? 'is' : 'is not'} a valid field`).join('\n'));

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!