I'm struggling to create a successful regex using Yup. I want to validate a string that it only accepts letters, numbers and spaces. Any other character would invalidate the entire string. This is my code:
const nameRegex = /^[^a-zA-Z0-9 ]+$/g;
export const Schema = Yup.object().shape({
name: Yup.string()
.required('Name is Required')
.matches(nameRegex, 'Name is not valid')
});
No matter what String I use, I get "Name is not valid" error from Yup.
"Tester 1" should pass and "Tester!% 2" should fail
How do I fix this?