feat: implement user registration page with form validation, authentication integration, and Quasar notifications.

This commit is contained in:
supalerk-ar66 2026-02-11 15:32:31 +07:00
parent dd5aacea3a
commit d7a91efa7b

View file

@ -103,13 +103,40 @@ const onUsernameInput = (val: string | number | null) => {
} }
}; };
const onPhoneInput = (val: string | number | null) => { const onPhoneInput = (e: Event) => {
const value = String(val || '') const input = e.target as HTMLInputElement
registerForm.phone = value; let value = input.value
if (/\D/.test(value)) {
errors.value.phone = 'กรุณากรอกเฉพาะตัวเลข'; // ( Copy-Paste)
} else { value = value.replace(/\D/g, '')
if (errors.value.phone === 'กรุณากรอกเฉพาะตัวเลข') clearFieldError('phone');
// 10
if (value.length > 10) {
value = value.substring(0, 10)
}
// Input
input.value = value
registerForm.phone = value
// error
if (value.length <= 10) {
clearFieldError('phone');
}
};
const onPhoneKeydown = (e: KeyboardEvent) => {
// Backspace, Tab, Enter,
const controlKeys = ['Backspace', 'Tab', 'Enter', 'Escape', 'ArrowLeft', 'ArrowRight', 'Delete', 'v', 'c', 'a'];
// Ctrl/Command + Key ( Ctrl+V)
if (e.ctrlKey || e.metaKey) {
if (controlKeys.includes(e.key.toLowerCase())) return;
}
//
if (!controlKeys.includes(e.key) && !/^\d$/.test(e.key)) {
e.preventDefault();
} }
}; };
@ -325,8 +352,10 @@ const handleRegister = async () => {
</div> </div>
<input <input
:value="registerForm.phone" :value="registerForm.phone"
@input="(e) => onPhoneInput((e.target as HTMLInputElement).value)" @input="onPhoneInput"
@keydown="onPhoneKeydown"
type="tel" type="tel"
maxlength="10"
class="w-full h-12 pl-12 pr-4 rounded-xl bg-slate-50 border border-slate-200 text-slate-900 placeholder-slate-400 text-base focus:outline-none focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 transition-all font-medium" class="w-full h-12 pl-12 pr-4 rounded-xl bg-slate-50 border border-slate-200 text-slate-900 placeholder-slate-400 text-base focus:outline-none focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 transition-all font-medium"
:class="{'border-red-500 focus:ring-red-500/20 focus:border-red-500': errors.phone}" :class="{'border-red-500 focus:ring-red-500/20 focus:border-red-500': errors.phone}"
/> />