Reputation: 707
I have a regex built to exclude all special charecters - /^\s*[a-zA-Z0-9,\s]+\s*$/ How could I change this regex to exclude special characters except for hyphen so users can enter numbers with dashes
Upvotes: 0
Views: 112
Reputation: 1850
just add dash in your set:
/^\s*[a-zA-Z0-9,\s-]+\s*$/
and you can optimize it a bit:
/^\s*[A-Za-z\d,\s-]+\s*$/
\d - means all digits
@MikeM, you're right. done! Changed back A-z to A-Za-z as @MikeM noticed.
Upvotes: 2