0

I want to check if my string is numbers or numbers and comma, no other character is allowed.

That's my try:

if(myStr.match(/\d+(,\d+)*/g)) {
        console.log("valid");
} else {
        console.log("not valid"); 
}

It doesn't work as I wants, for example:

myStr = "12,15,as";

is "valid", but it shouldnt.

How can I fix it?

cucuru
  • 3,456
  • 8
  • 40
  • 74

0 Answers0