I'm using YUP in order to validate some fields in my form (formik for React).
one of those fields is a user name the user needs to choose.
I want the ability to mark some special words as not valid, using regex.
for example, the word "admin" (or "Admin" or any other combination of it) is not allowed
according to YUP documentation:
https://github.com/jquense/yup#stringmatchesregex-regex-message-string--function-schema
but the example shows only a list of valid word, not invalid word
i tried:
userName: Yup.string().matches(/^(Admin|admin)/, 'admin is not a valid user name').required('Required'),
but even this simple regext is not working
so, how to write a regex that negates a word (preferably with all the case combinations)?
thanks!
/^(?!admin\b)/i
– anubhava