refactor: 提取正则和验证到 @vben/utils

This commit is contained in:
xingyu4j
2025-09-03 16:46:22 +08:00
parent 44eebda749
commit deb412662e
10 changed files with 46 additions and 51 deletions

View File

@@ -7,10 +7,7 @@ import type { ComponentType } from './component';
import { setupVbenForm, useVbenForm as useForm, z } from '@vben/common-ui';
import { $t } from '@vben/locales';
// TODO @xingyu要不搞到全局的校验
/** 手机号正则表达式(中国) */
const MOBILE_REGEX = /(?:0|86|\+86)?1[3-9]\d{9}/;
import { isMobile } from '@vben/utils';
async function initSetupVbenForm() {
setupVbenForm<ComponentType>({
@@ -45,7 +42,7 @@ async function initSetupVbenForm() {
mobile: (value, _params, ctx) => {
if (value === undefined || value === null || value.length === 0) {
return true;
} else if (!MOBILE_REGEX.test(value)) {
} else if (!isMobile(value)) {
return $t('ui.formRules.mobile', [ctx.label]);
}
return true;
@@ -55,7 +52,7 @@ async function initSetupVbenForm() {
if (value === undefined || value === null || value.length === 0) {
return $t('ui.formRules.required', [ctx.label]);
}
if (!MOBILE_REGEX.test(value)) {
if (!isMobile(value)) {
return $t('ui.formRules.mobile', [ctx.label]);
}
return true;