diff --git a/Frontend-Learner/components/profile/ProfileEditForm.vue b/Frontend-Learner/components/profile/ProfileEditForm.vue index 60607e6d..d7fc85bf 100644 --- a/Frontend-Learner/components/profile/ProfileEditForm.vue +++ b/Frontend-Learner/components/profile/ProfileEditForm.vue @@ -40,6 +40,30 @@ const handleFileUpload = (event: Event) => { emit('upload', target.files[0]); } }; + +const onPhoneInput = (val: string | number | null) => { + let value = String(val || ''); + // กรองเฉพาะตัวเลขเผื่อการป้อนข้อมูลวิธีอื่น + value = value.replace(/\D/g, ''); + if (value.length > 10) { + value = value.substring(0, 10); + } + props.modelValue.phone = value; +}; + +const onPhoneKeydown = (e: KeyboardEvent) => { + // อนุญาตให้กดปุ่มควบคุมต่างๆ ได้ + const controlKeys = ['Backspace', 'Tab', 'Enter', 'Escape', 'ArrowLeft', 'ArrowRight', 'Delete', 'v', 'c', 'a']; + + if (e.ctrlKey || e.metaKey) { + if (controlKeys.includes(e.key.toLowerCase())) return; + } + + // ป้องกันการกรอกตัวอักษร + if (!controlKeys.includes(e.key) && !/^\d$/.test(e.key)) { + e.preventDefault(); + } +};