Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript - String contains commas and dashes

I have a quick question.

How do I check whether there are any commas or dashes in a string? Thx

like image 556
chris97ong Avatar asked Feb 19 '26 16:02

chris97ong


2 Answers

/[,\-]/.test(yourString)

this returns true if yourString contains commas or dashes or false otherwise.

like image 183
kamilkp Avatar answered Feb 21 '26 06:02

kamilkp


/(,|-)/.test(yourString); // returns true if there are commas or dashes in the string, false otherwise.
like image 24
Sébastien Avatar answered Feb 21 '26 06:02

Sébastien



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!