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

182
Views
Vuetify validation rules for string numeric combination

I am trying to determine how to use Vuetify validation to ensure the rules (using :rules tag on a v-text-field) meet this format:

AB-12345678 (first two characters are letters followed by hyphen then 8 digit number)

I am struggling to do this without using CharAt but I assume there is a cleaner and simpler method.

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

0

you can use regex to check vailation

regex rule: [A-B]{2}-[0-9]{8}

check the code

<template>   
  <v-text-field
      :rules="customRule"
  />
</template>

<script>

export default {
  computed: {
    customRule() {
      return [
        v => /[A-B]{2}\-[0-9]{8}/.test(v) || "rule is not valid"
      ],
    }
  }
}

</script>
about 4 years ago · Juan Pablo Isaza Report

0

I'd use regex

<v-text-field
  :rules="[v => /^[A-Z]{2}-\d{8}$/gm.test(v)]"
/>

It depends on exactly what you want but this regex is doing:

  • ^ match start of line
  • [A-Z]{2} match exactly 2 uppercase characters
    • Use [A-Za-z]{2} if upper/lowercase doesn't matter
  • - match a dash
  • \d{8} match 8 digits
  • $ match end of line
  • gm at the end are flags for the regex

Here's a page to test it

about 4 years ago · Juan Pablo Isaza Report

0

You should consider using Regular Expressions. Something like : ^[A-Z]{2}-[0-9]{8}$ should work.

To use Regex in javascript, you should refer to the Mozilla developers docs

It looks like this :

const paragraph = 'The quick brown fox jumps over the lazy dog. It barked.';
const regex = /[A-Z]/g;
const found = paragraph.match(regex);

console.log(found);
// expected output: Array ["T", "I"]

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!