Try:
var regex = /^[0-9\,\s]+$/;
سؤال
I need help with a regular expression to allow only numbers, commas, and whitespaces in JavaScript.
For example :
"123456,78889,871253,85879" valid
",12002, 102878,11000"   valid
"77,1293,abc" not valid (Due to the abc)
So far I have got :
var regex = new RegExp("[^0-9]|[^\,]|[^\s]");
if (regex.exec(myValue) === null) {
// value is valid
}
نصائح أخرى
have you tried this one? /^[0-9, ]*$/ it should be enough
/^[0-9,\s]*$/.test("1234565, 123545, abc");
this returns false