October 29, 2010

Validate Decimal onKeyup in JS

//OnKeyup
function VD(txt)
{
if (txt.value.split('.').length > 2)
{
txt.value = txt.value.substr(0, txt.value.length-1);
}
}

Note: http://asquare.net/javascript/tests/KeyCode.html
// OnKeyPress
function ValidateDecimal(event) {
var keynum;
if(window.event) // IE
{
keynum = event.keyCode;
if (!((keynum >= 48 && keynum <= 57) || keynum == 46 || keynum == 37 || keynum == 39 || keynum == 8 || keynum == 9)) {
return false; }
}
else if(event.which) // Netscape/Firefox/Opera
{
keynum = event.which;
if (!((keynum >= 48 && keynum <= 57) || keynum == 0 || keynum == 9)) {
return false; }
}

}

No comments:

SonarQube with Jenkins Setup using Docker Images

https://funnelgarden.com/sonarqube-jenkins-docker/  https://medium.com/@hakdogan/an-end-to-end-tutorial-to-continuous-integration-and-con...