This commit is contained in:
2026-06-30 22:19:27 +03:30
parent 15c43a8ee9
commit bbec5b802d
11 changed files with 178 additions and 40 deletions
+3 -2
View File
@@ -33,12 +33,13 @@ import type {Rule} from 'ant-design-vue/es/form'
import {useWalletStore} from "@/store/walletStore";
import { isCashLikeDealMethod, isMainMetalWalletDealMethod, getInsufficientCashWalletMessage, getInsufficientGoldWalletMessage } from '@/utils/productDealMethod'
import { getCashWalletBalance } from '@/utils/productAssets'
import { persianToEnglishDigits } from '@/utils/persianDigits'
export const mobileValidation = (title?: string): Rule => {
const label = title ?? 'شماره تلفن'
return {
validator: (_rule, value) => {
const normalized = String(value ?? '').trim()
const normalized = persianToEnglishDigits(String(value ?? '').trim())
if (!normalized) {
return Promise.resolve()
}
@@ -273,7 +274,7 @@ export const passwordRules = () => {
export const englishNumberRule = () => {
return {
validator: (_: any, value: string | number) => {
const str = value != null ? String(value) : ''
const str = persianToEnglishDigits(value)
if (!str) return Promise.resolve()
const isEnglishDigitsOnly = /^[0-9]+$/.test(str)
if (!isEnglishDigitsOnly) {
+29
View File
@@ -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'
}