Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // src/@types/yup.d.ts
- import { StringSchema } from "yup";
- import type { schema } from 'modules/common/phone';
- declare module "yup" {
- interface StringSchema {
- phone: typeof schema;
- }
- }
- // src/modules/common/phone/schema.ts
- import * as yup from 'yup';
- export function schema(this: yup.StringSchema) {
- return this.test(
- 'phoneFormat',
- (value?: string) => (
- value != null ? /\+7\s\(\d{3}\)\s\d{3}-\d{2}-\d{2}/.test(value) : true
- ),
- );
- }
- yup.addMethod(yup.string, 'phone', schema);
Add Comment
Please, Sign In to add comment