How to validate numeric values which may contain dots or commas?

user256034 picture user256034 · Mar 28, 2011 · Viewed 247.6k times · Source

I need a regular expression for validation two or one numbers then , or . and again two or one numbers.

So, these are valid inputs:

11,11  
11.11  
1.1  
1,1  

Answer

user237419 picture user237419 · Mar 28, 2011
\d{1,2}[\,\.]{1}\d{1,2}

EDIT: update to meet the new requirements (comments) ;)
EDIT: remove unnecesary qtfier as per Bryan

^[0-9]{1,2}([,.][0-9]{1,2})?$