...

View Full Version : I need javascript code to eliminate ascii/letters from text field



bsharif
06-28-2006, 03:41 PM
Hello to all, I need javascript code to eliminate ascii/letters from text field , text field should only allow users to input numbers and I need it to happen on a onblur and onkey function.

please help point me in the right direction.

Thanks:thumbsup:

Kor
06-28-2006, 03:54 PM
Regular Expressions do that:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/JavaScript">
function valid(f) {
if (!/^\d*$/.test(f.value)) {
f.value = f.value.replace(/[^\d]/g,"");
}
}
</script>
</head>
<body>
<input type="text" onkeyup="valid(this)" onblur="valid(this)">
</body>
</html>

bsharif
06-28-2006, 04:00 PM
Thank you very much , well appreciated.

Life saver



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum