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

171
Views
Validation of Employee id using regular expression using Javascript/Vue.JS

I would like to create a REGEX for Employee Numbers.

The employee number must be a numerical value ONLY and must have a minimum of 8 values. The part after the hyphen can be optional but limited to two digits as below.

12345678 12345678-12

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

^\d{8} => Starts with 8 numbers

(-\d{2})? => has optional ending of a dash followed by 2 numbers

$ makes sure that the ending has to be either 8 numbers or the optional part after 8 numbers

function validateEmployeeNumber(number) {
  return (/^\d{8}(-\d{2})?$/).test(number)
}

console.log(validateEmployeeNumber(12345678)) // true
console.log(validateEmployeeNumber("12345678")) // true
console.log(validateEmployeeNumber("12345678-12")) // true

console.log(validateEmployeeNumber("1234567")) // false
console.log(validateEmployeeNumber("123456789")) // false
console.log(validateEmployeeNumber("12345678-123")) // false
console.log(validateEmployeeNumber("12345678-")) // false

I never used Vue, but this should be fine:

fd.field('Numeric').validators;
fd.field('Numeric').validators.push({
    name: 'MyCustomValidator',
    error: '',
    validate: function(value) {
        if ((/^\d{8}(-\d{2})?$/).test(value)) {
            return true; // Validation succeded
        }
        // You land here if it did not succeed
        this.error = 'Value is not valid';
        return false;
    }
});
about 4 years ago · Santiago Gelvez 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!