Allow only comma separated numbers in input field using angular js
<p>I am using angular js and below is my code which allows only numbers separated by comma.But regex which I used allows user to enter 1,,,2.</p>

<p>Is there any way so that I can restrict user to enter only one comma after each number?</p>

<p>Plunker - <a href="http://plnkr.co/edit/g1X9ldVuH4ZewAlumM1P?p=preview" rel="nofollow">http://plnkr.co/edit/g1X9ldVuH4ZewAlumM1P?p=preview</a></p>

<pre><code>  function NumberValidator() {
    return {
        require: '?ngModel',
        link: function(scope, element, attrs, ngModelCtrl) {
            if (!ngModelCtrl) {
                return;
            }

            ngModelCtrl.$parsers.push(function(val) {
                var clean = val.replace(/[^\d+(,\d+)*$]/g, '');
                if (val !== clean) {
                    ngModelCtrl.$setViewValue(clean);
                    ngModelCtrl.$render();
                }
                return clean;
            });

            element.bind('keypress', function(event) {
                if (event.keyCode === 32) {
                    event.preventDefault();
                }
            });
        }
    };
</code></pre>