refactor: add rules

This commit is contained in:
Thanaphon Frappet 2024-10-15 11:14:30 +07:00
parent 1fb2606885
commit 132f533fd0
2 changed files with 18 additions and 3 deletions

View file

@ -305,7 +305,14 @@ watch(districtId, fetchSubDistrict);
:rules="
disabledRule
? []
: [(val) => (val && val.length > 0) || $t('form.error.required')]
: [
(val) => (val && val.length > 0) || $t('form.error.required'),
(val) =>
(val && val.length === 11 && /[0-9]+/.test(val)) ||
$t('form.error.invalidCustomeMessage', {
msg: $t('form.error.requireLength', { msg: 11 }),
}),
]
"
/>
<q-input

View file

@ -382,7 +382,11 @@ watch(
class="col"
label="Name"
v-model="firstNameEN"
:rules="[(val: string) => !!val || $t('form.error.required')]"
:rules="[
(val: string) => !!val || $t('form.error.required'),
(val: string) =>
/^[A-Za-z]+$/.test(val) || $t('form.error.letterOnly'),
]"
/>
<q-input
:for="`${prefixId}-input-last-name`"
@ -393,7 +397,11 @@ watch(
class="col"
label="Surname"
v-model="lastNameEN"
:rules="[(val: string) => !!val || $t('form.error.required')]"
:rules="[
(val: string) => !!val || $t('form.error.required'),
(val: string) =>
/^[A-Za-z]+$/.test(val) || $t('form.error.letterOnly'),
]"
/>
</div>