I want to make sure users don't fill in their username (pattern is a upercase or lowercase u, followed by 7-10 digits: U0000000
)
In the following example, the regex itself does work. However in conjunction with the .matches()
method it does not validate the field.
const schema = Yup.object()
.shape({
myField: Yup.string()
.matches(/.*\d/, 'Should contain a digit') // <- this works
.matches(/(?!.*[uU]\d{7,10})/, 'Should not contain a user ID') // <- this does not
});