the0938

Untitled

Mar 24th, 2021 (edited)
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. // src/@types/yup.d.ts
  2. import { StringSchema } from "yup";
  3.  
  4. import type { schema } from 'modules/common/phone';
  5.  
  6. declare module "yup" {
  7. interface StringSchema {
  8. phone: typeof schema;
  9. }
  10. }
  11.  
  12. // src/modules/common/phone/schema.ts
  13. import * as yup from 'yup';
  14.  
  15. export function schema(this: yup.StringSchema) {
  16. return this.test(
  17. 'phoneFormat',
  18. (value?: string) => (
  19. value != null ? /\+7\s\(\d{3}\)\s\d{3}-\d{2}-\d{2}/.test(value) : true
  20. ),
  21. );
  22. }
  23.  
  24. yup.addMethod(yup.string, 'phone', schema);
  25.  
Add Comment
Please, Sign In to add comment