0
votes

So I have a problem with my yup validation. I want to make sure that for my name field the user can enter only letters or spaces. However no matter what I type in my field it keeps telling me it is incorrect.

const letterRegex = new RegExp("/^[a-zA-Z\s]*$/");

const pg_BinnenCoLoondienst: yup.SchemaOf<RowBinnenCoLoonDienstData> = yup
  .object()
  .shape({
    REV_PE_BCL_Naam: yup.string().required("Name is required").matches(letterRegex, "Name can only contain letters & spacces"),

If I remove the matches part and only use required than it works perfectly so the issue is with the 'matches' part of the validation.

result

Anyone sees what I'm doing wrong? Thx!

1

1 Answers

1
votes

You can use this regex

const letterRegex = new RegExp("^[a-zA-Z ]*$");