Add:Login validation & error alerts for user safety
This commit is contained in:
parent
bb80b8a419
commit
3c86933dee
6 changed files with 25 additions and 12 deletions
|
|
@ -30,7 +30,11 @@ const loginForm = reactive({
|
|||
// Validation rules definition
|
||||
const loginRules = {
|
||||
email: {
|
||||
rules: { required: true, email: true },
|
||||
rules: {
|
||||
required: true,
|
||||
email: true,
|
||||
custom: (val: string) => /[\u0E00-\u0E7F]/.test(val) ? 'ห้ามใส่ภาษาไทย' : null
|
||||
},
|
||||
label: 'อีเมล',
|
||||
messages: {
|
||||
required: 'กรุณากรอกอีเมลของคุณ',
|
||||
|
|
@ -38,7 +42,11 @@ const loginRules = {
|
|||
}
|
||||
},
|
||||
password: {
|
||||
rules: { required: true, minLength: 8 },
|
||||
rules: {
|
||||
required: true,
|
||||
minLength: 8,
|
||||
custom: (val: string) => /[\u0E00-\u0E7F]/.test(val) ? 'ห้ามใส่ภาษาไทย' : null
|
||||
},
|
||||
label: 'รหัสผ่าน',
|
||||
messages: {
|
||||
required: 'กรุณากรอกรหัสผ่าน',
|
||||
|
|
@ -55,9 +63,14 @@ const loginRules = {
|
|||
* Handles input updates, stripping Thai characters and clearing errors.
|
||||
*/
|
||||
const handleInput = (field: keyof typeof loginForm, value: string) => {
|
||||
// Remove Thai characters range \u0E00-\u0E7F
|
||||
loginForm[field] = value.replace(/[\u0E00-\u0E7F]/g, '')
|
||||
clearFieldError(field)
|
||||
loginForm[field] = value
|
||||
if (/[\u0E00-\u0E7F]/.test(value)) {
|
||||
errors.value[field] = 'ห้ามใส่ภาษาไทย'
|
||||
} else {
|
||||
if (errors.value[field] === 'ห้ามใส่ภาษาไทย') {
|
||||
clearFieldError(field)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleLogin = async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue