View Full Version : Disable comas, dot (.)
petertran123
08-09-2002, 02:49 PM
Hello All,
I have a form with name and address. I wanted to validate the field for not allowing enter comas(,) or dot(.) and Amp. (&) . The field only except Characters and Numerics. Is there anyway i can do it.. Please help for codings. Thanks
requestcode
08-09-2002, 04:25 PM
You could set up a regular expression to do this. Here is an example:
re1=/[^a-zA-Z0-9]/
function checknum1()
{
myvar1=document.form_name.field_name.value
if(myvar1.match(re1)||myvar1.length==0)
{
alert("Invalid!")
}
else
{alert("Correct!")}
}
adios
08-10-2002, 12:20 AM
I always like to filter the input in advance rather than validating/correcting later. The only question: the dot character is often used in addresses....
<html>
<head>
<script type="text/javascript">
function filter(e) {
var chr;
if (e && e.keyCode) chr = String.fromCharCode(e.keyCode);
if (e&& e.which) chr = String.fromCharCode(e.which);
if (chr) return /[a-zA-Z0-9]/.test(chr);
else return true;
}
</script>
</head>
<body>
<form>
<input onkeypress="return filter(event)">
</form>
</body>
</html>
To allow a period:
/[a-zA-Z0-9\.]/
petertran123
08-12-2002, 02:20 PM
Thank you very much for your help..
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.