Update validate data

This commit is contained in:
ThienPhamVan
2026-03-25 16:03:35 +07:00
parent 3a2e16cf19
commit e7e8f0b38a
3 changed files with 150 additions and 98 deletions

View File

@@ -297,5 +297,97 @@ Vue.use({
const regexFullName = /^[A-Za-zÀ-ỹ]+(\s[A-Za-zÀ-ỹ]+)+$/;
return regexFullName.test(fullName);
};
Vue.prototype.$validateEmail = function (email, isNull = false) {
const value = (email || '').trim().toLowerCase();
if (!isNull && !value) {
return {
status: false,
message: 'Email không được bỏ trống.',
};
}
if (value && !this.$regexEmail(value)) {
return {
status: false,
message: 'Email không hợp lệ. Vui lòng nhập đúng định dạng (ví dụ: ex@gmail.com).',
};
}
return {
status: true,
message: '',
};
};
Vue.prototype.$validatePassword = function (password, isNull = false) {
const value = (password || '').trim();
if (!isNull && !value) {
return {
status: false,
message: 'Mật khẩu không được bỏ trống.',
};
}
if (value && !this.$regexPassword(value)) {
return {
status: false,
message: 'Mật khẩu không hợp lệ. Phải có ít nhất 8 ký tự, bao gồm chữ hoa, chữ thường, số và ký tự đặc biệt.',
};
}
return {
status: true,
message: '',
};
};
Vue.prototype.$validatePhone = function (phone, isNull = false) {
const value = (phone || '').trim();
if (!isNull && !value) {
return {
status: false,
message: 'Số điện thoại không được bỏ trống.',
};
}
if (value && !this.$regexPhone(value)) {
return {
status: false,
message: 'Số điện thoại không hợp lệ. Vui lòng nhập số điện thoại Việt Nam hợp lệ (ví dụ: 0912345678).',
};
}
return {
status: true,
message: '',
};
};
Vue.prototype.$validateFullName = function (fullName, isNull = false) {
const value = (fullName || '').trim();
if (!isNull && !value) {
return {
status: false,
message: 'Họ và tên không được bỏ trống.',
};
}
if (value && !this.$regexFullName(value)) {
return {
status: false,
message: 'Họ và tên không hợp lệ. Vui lòng nhập họ và tên đầy đủ.',
};
}
return {
status: true,
message: '',
};
};
},
});