Files
dukang/apps/mini-user/src/lib/user-phone.ts
T
2026-07-12 19:44:36 +08:00

23 lines
519 B
TypeScript

import Taro from '@tarojs/taro';
const USER_PHONE_KEY = 'user_phone';
export function saveUserPhone(phone: string) {
const normalized = phone.replace(/\D/g, '').slice(0, 11);
if (!/^1[3-9]\d{9}$/.test(normalized)) return;
try {
Taro.setStorageSync(USER_PHONE_KEY, normalized);
} catch {
/* ignore */
}
}
export function getStoredUserPhone(): string {
try {
const value = Taro.getStorageSync(USER_PHONE_KEY);
return typeof value === 'string' ? value : '';
} catch {
return '';
}
}