<script>
function onlyDecimals(evt){
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
} else {
// If the number field already has . then don't allow to enter . again.
if (evt.target.value.search(/\./) > -1 && charCode == 46) {
return false;
}
return true;
}
}
</script>
Bind the following code in jsp file
<td><s:textfield name="textfieldname" value="%{ftextfieldname}" id="textfieldnameId" dir="rtl" onkeypress="return onlyDecimal(event);"/></td>
function onlyDecimals(evt){
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
} else {
// If the number field already has . then don't allow to enter . again.
if (evt.target.value.search(/\./) > -1 && charCode == 46) {
return false;
}
return true;
}
}
</script>
Bind the following code in jsp file
<td><s:textfield name="textfieldname" value="%{ftextfieldname}" id="textfieldnameId" dir="rtl" onkeypress="return onlyDecimal(event);"/></td>