I have a jsbin --> https://jsbin.com/yipigicuve/edit?html,console,output
As per the link, i have the following code
<input ng-keypress="Num($event)" type="number" step=".1" ng-pattern="/^[+-]?(?:\d+\.?\d*|\d*\.?\d+)[\r\n]*$|^$/" ng-model="dataip"></>
$scope.Num = function (event) {
var keys = {
'up': 38, 'right': 39, 'down': 40, 'left': 37,
'escape': 27, 'backspace': 8, 'tab': 9, 'enter': 13, 'del': 46,
'0': 48, '1': 49, '2': 50, '3': 51, '4': 52, '5': 53, '6': 54, '7': 55, '8': 56, '9': 57, 'dash':189, 'subtract':109
};
for (var index in keys) {
if (!keys.hasOwnProperty(index)) continue;
if (event.charCode == keys[index] || event.keyCode == keys[index]) {
return; //default event
}
}
event.preventDefault();
};
User enters alphabets and those are not accepted. There are certain alphanumeric keys which is accepted as shown in variable 'keys'
Certain patterns are presented so that null values, decimal point can be accepted.
My problem is....the current input type in the jsbin accepts values such as '-2.34---45' or '3.4...345"
It should accept decimal point and negative sign only once. i.e. '3.5566' or '-23.33'
Can someone let me know how to use ng-pattern to achieve my conditions.