SES-713
HTML
Input Value: 0.060693571726285485
<br>
<input type='text' onkeypress='validate(event)' value="0.060693571726285485" />
JavaScript 1.7
function validate(evt) {
var theEvent = evt || window.event;
let inputTextValue = theEvent.target.value;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode(key);
if (key === '\b') {
if (inputTextValue.length > 0) {
inputTextValue = inputTextValue.substring(0, inputTextValue.length - 1);
}
} else {
inputTextValue = inputTextValue + key;
}
var regex = /^[-]?[0-9]*\.?[0-9]*$/;
console.log(inputTextValue);
if (!regex.test(inputTextValue)) {
theEvent.returnValue = false;
if (theEvent.preventDefault) theEvent.preventDefault();
}
}
window.validate = validate;