Reputation: 407
I am using regex ISMatch method to check that string contains only numbers and comma and accept below two types
EX-> 123,456 Accepted
EX-> 123,456, Accepted
I am using below regex but it does not works it pass string with alphabets too
[0-9]+(,[0-9]+)*,?
Can anyone help me ?
Upvotes: 0
Views: 3122
Reputation: 348
Here's the simplest regex:
^\d*[,]\d*$
However, this will succeed for just , with no digits. If you require at least one digit either before or after the comma or dot, I think this is it:
^(\d+[,]\d*|\d*[,]\d+)$
If the comma is optional rather than required, add ? after [,].
Upvotes: 1