mirror of
https://github.com/sergeyyarkov/educt-client.git
synced 2026-10-11 10:19:22 +03:00
26 lines
612 B
TypeScript
26 lines
612 B
TypeScript
import * as yup from 'yup';
|
|
import validator from 'validator';
|
|
import isMobilePhone from 'validator/lib/isMobilePhone';
|
|
import { string, StringSchema } from 'yup';
|
|
|
|
/**
|
|
* Delcare custom methods
|
|
*/
|
|
yup.addMethod<StringSchema>(
|
|
string,
|
|
'isMobileValid',
|
|
function (
|
|
this: StringSchema,
|
|
locales: validator.MobilePhoneLocale[],
|
|
options?: validator.IsMobilePhoneOptions | undefined
|
|
) {
|
|
return this.test({
|
|
name: 'isMobileValid',
|
|
message: 'Phone number is not valid',
|
|
test: value => (!value ? true : isMobilePhone(value, locales, options)),
|
|
});
|
|
}
|
|
);
|
|
|
|
export default yup;
|