user441521
user441521

Reputation: 6998

Regex not accepting numbers

I can't figure out why this regex pattern isn't accepting numbers? It used to but then I added [()#'/- part and it stopped.

^[()#'/-0-9A-Za-z ]+$

Upvotes: 1

Views: 43

Answers (2)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626845

The /-0 created a valid range that only matches / or 0:

enter image description here

So, your regex could match a string with 0 and 9 in it (like ()#'/0-9ABCZab c), but not the whole digit range.

Replace with

^[-()#'/0-9A-Za-z ]+$

See the regex demo

Upvotes: 2

devil_coder
devil_coder

Reputation: 1135

Take "-" out before "0"

^[()#'/0-9A-Za-z ]+$

Upvotes: 1

Related Questions