<%--
Document : decimlOnly
Created on : Dec 21, 2009, 4:29:43 PM
Author : user02
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script>
function intOnly(i) {
var t = i.value;
if(t.length>0) {
t = t.replace(/[^\d\.]+/g, '');
}
var s = t.split('.');
if(s.length>1) {
s[1] = s[0] ;//+ '.' + s[1];
s.shift(s);
}
i.value = s.join('');
}
function decimalOnly(i) {
var t = i.value;
if(t.length>0) {
t = t.replace(/[^\d\.]+/g, '');
}
var s = t.split('.');
if(s.length>1) {
s[1] = s[0]+ '.' + s[1];
s.shift(s);
}
i.value = s.join('');
}
</script>
</head>
<body>
test <input type="text" onchange="decimalOnly(this);" onkeyup="decimalOnly(this);" onkeypress="decimalOnly(this);">
</body>
</html>
No comments:
Post a Comment