-2

I'm using a name validation in Javascript. I found this code on internet. It's working fine.

I'm not getting why do we need to use the asterisk(*) symbol here? Code is not working without this also.

var pattern=/^([A-Za-z ]*)$/g;
ADyson
  • 57,178
  • 14
  • 51
  • 63
Subhadeep
  • 30
  • 9
  • 2
    Does this answer your question? [Reference - What does this regex mean?](https://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) – Cristik Sep 22 '21 at 11:45

2 Answers2

1

It's to matches any length of that capture group (([A-Za-z ])). I would recommend https://regexr.com/ if you run in to problems with regex as it includes a good explanation for all expressions

ueberflieger
  • 11
  • 1
  • 4
0

It Matches the preceding item "x" 0 or more times in ([A-Za-z ]). Read this : Quantifiers in Javascript