fix bugs
This commit is contained in:
+16
-2
@@ -32,9 +32,23 @@ import { computed, ref } from 'vue'
|
||||
import type { Rule } from 'ant-design-vue/es/form'
|
||||
import { useWalletStore } from '@/store/walletStore'
|
||||
import {isToken} from "@/utils/index";
|
||||
import { persianToEnglishDigits } from '@/utils/persianDigits'
|
||||
|
||||
export const mobileValidation = (title?: string) => {
|
||||
return { len: 11, message: `شماره همراه باید 11 رقم باشد` }
|
||||
export const mobileValidation = (title?: string): Rule => {
|
||||
const label = title ?? 'شماره تلفن'
|
||||
return {
|
||||
validator: (_rule, value) => {
|
||||
const normalized = persianToEnglishDigits(String(value ?? '').trim())
|
||||
if (!normalized) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
if (!/^09\d{9}$/.test(normalized)) {
|
||||
return Promise.reject(`${label} باید با 09 شروع شود و 11 رقم باشد`)
|
||||
}
|
||||
return Promise.resolve()
|
||||
},
|
||||
trigger: ['change', 'blur'],
|
||||
}
|
||||
}
|
||||
|
||||
export const required = (title?: string) => {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
const PERSIAN_DIGITS = '۰۱۲۳۴۵۶۷۸۹'
|
||||
const ARABIC_DIGITS = '٠١٢٣٤٥٦٧٨٩'
|
||||
|
||||
/** تبدیل ارقام فارسی/عربی و جداکننده اعشار به فرمت انگلیسی */
|
||||
export function persianToEnglishDigits(value: string | number | null | undefined): string {
|
||||
if (value == null) {
|
||||
return ''
|
||||
}
|
||||
|
||||
return String(value)
|
||||
.replace(/[۰-۹]/g, (d) => String(PERSIAN_DIGITS.indexOf(d)))
|
||||
.replace(/[٠-٩]/g, (d) => String(ARABIC_DIGITS.indexOf(d)))
|
||||
.replace(/٫/g, '.')
|
||||
}
|
||||
|
||||
export function shouldNormalizeInputDigits(options: {
|
||||
isPassword?: boolean
|
||||
type?: string
|
||||
inputmode?: string
|
||||
}): boolean {
|
||||
if (options.isPassword) {
|
||||
return false
|
||||
}
|
||||
if (options.type === 'price' || options.type === 'number') {
|
||||
return true
|
||||
}
|
||||
const mode = String(options.inputmode ?? '').trim().toLowerCase()
|
||||
return mode === 'numeric' || mode === 'decimal' || mode === 'number'
|
||||
}
|
||||
Reference in New Issue
Block a user