Hi Floks ,
Here I am giving the simple JS function , which will accept decimals in to text box on visualforce page,
JS code snippet :
function IsDecimal(myField, e) {
var keynum;
var keychar;
var numcheck;
if (window.event) // IE
{
keynum = e.keyCode;
}
else if (e.which) // Netscape/Firefox/Opera
{
keynum = e.which;
}
var charCode = (e.which) ? e.which : event.keyCode
if(charCode != 46){
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
}
if(e.which==0)
return true;
keychar = String.fromCharCode(keynum);
if (keychar == '.') {
var val = myField.value;
if (val.split(keychar).length > 1)
return false;
}
return true;
}
How to call :
<apex:inputText value="{!dtest}" id="testID" onkeypress="return IsDecimal(this,event)" />
Thank you.
Here I am giving the simple JS function , which will accept decimals in to text box on visualforce page,
JS code snippet :
function IsDecimal(myField, e) {
var keynum;
var keychar;
var numcheck;
if (window.event) // IE
{
keynum = e.keyCode;
}
else if (e.which) // Netscape/Firefox/Opera
{
keynum = e.which;
}
var charCode = (e.which) ? e.which : event.keyCode
if(charCode != 46){
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
}
if(e.which==0)
return true;
keychar = String.fromCharCode(keynum);
if (keychar == '.') {
var val = myField.value;
if (val.split(keychar).length > 1)
return false;
}
return true;
}
How to call :
<apex:inputText value="{!dtest}" id="testID" onkeypress="return IsDecimal(this,event)" />
Thank you.
No comments:
Post a Comment