-1

I can't find out why my regex is accepting some values.

const regexNome = /([A-z]+\s?)+/g;

It's accepting values like "jhon 123" and I want only names (it's for a name input validation).

Can you help me?

Laurel
  • 5,771
  • 12
  • 29
  • 54
  • 1
    See [here](https://regex101.com/r/0Ob70M/1) why. – Wiktor Stribiżew May 18 '22 at 19:08
  • If you add a dollar sign at the end (`([A-z]+\s?)+$`), it works as expected. – John Slegers May 18 '22 at 19:11
  • Regex will match any part of the string, unless you tell it NOT to do so by starting the pattern with a `^` and ending the pattern with a `$`. Furthermore, are you aware that `[A-z]` includes the characters ``[\]^`_`` ? If not, you might want to use `[A-Za-z]` instead. – Peter B May 18 '22 at 21:06

0 Answers0