1π
β
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
- Use
-
match a dash\d{8}
match 8 digits$
match end of linegm
at the end are flags for the regex
π€Josh G
2π
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>
π€Kareem Dabbeet
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"]
π€MrAnyx
Source:stackexchange.com