Reputation:
I have the following RegEx:
/[a-zA-Z\d ']{1,30}/
and the following string:
some text'&&
Now, that RegEx returns true on the string. I suppose that it matches the part without "&&". I'd like to ask how can I limit characters to alphanumeric characters, including space and apostrophes as the RegEx from above writes.
Upvotes: -1
Views: 40
Reputation: 526613
Anchor your regex:
/^[a-zA-Z\d ']{1,30}$/
^
means "start of string" and $
means "end of string" so adding those markers forces the regex to either match the entire string or not at all.
Upvotes: 5