bin2k
bin2k

Reputation: 53

In javascript how can i use regex to validate comma with other characters

In javascript how can i use regex to validate comma with characters. I'm doing this

return /^[a-zA-Z_-]+$/i.test(value);

which is working perfect but I want to add comma like this

return /^[a-zA-Z_-,]+$/i.test(value);

which is not working.

Upvotes: 2

Views: 373

Answers (1)

Karolis
Karolis

Reputation: 9562

Inside a character class, - is a special character (indicating a range between the preceding and the following character) unless it is the first or last character in the class:

return /^[a-zA-Z_,-]+$/i.test(value);

Upvotes: 6

Related Questions