View Full Version : Need Numeric and alphabetic Script
eshban
11-22-2005, 05:44 AM
Hello,
I need a java script, which just allow me to type numeric data in a text field.
I also need sperate script which allow to just type characters in field.
bye
missing-score
11-22-2005, 10:19 AM
Umm, well why don't you post in the javascript forum then? I'm going to move this there now...
numeric validator:
<!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) {
var re = /^[0-9]*$/;
if (!re.test(f.value)) {
alert("Only numbers allowed!");
f.value = f.value.replace(/[^0-9]/g,"");
}
}
</script>
</head>
<body>
<input name="" type="text" onkeyup="valid(this)">
</body>
</html>
Alpha numeric validator:
<!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) {
var re = /^[A-z]*$/;
if (!re.test(f.value)) {
alert("Only alpha numeric characters allowed!");
f.value = f.value.replace(/[^A-z]/g,"");
}
}
</script>
</head>
<body>
<input name="" type="text" onkeyup="valid(this)">
</body>
</html>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.