View Full Version : only numbers
angiras
02-19-2003, 08:10 AM
I want to allow only numbers into a textbox
and to display a message beside if not
<input type='text' /> [hiddend message = "only numbers !"]
thank you
Borgtex
02-19-2003, 11:54 AM
http://www.codingforums.com/showthread.php?s=&threadid=10374
angiras
02-19-2003, 01:28 PM
perfect !
thank you
angiras
02-19-2003, 03:21 PM
and how can you oblige only dates
MM/DD/YY ?
thank you again !
whammy
02-20-2003, 12:42 AM
Only numbers, I have written a specific script for that. This will not only prevent users from entering anything but digits in the first place, but if they paste them in it will still replace them using the extractNumeric() function - so you're covered both ways as long as the user has javascript enabled.
http://www.solidscripts.com/displayscript.asp?sid=12
For date format, you can use the same regular expression I use in ASP here, but just apply it to javascript:
http://www.solidscripts.com/downloads/functions.txt
Look for IsDateFormat() ...
^(\d{1,2})\/(\d{1,2})\/(\d{4})$
In javascript you'd do:
if (!/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.test(somestring)) {
return false;
}
P.S. If you aren't using a full year you'd want to change that "4" to a "2".
angiras
02-20-2003, 04:40 AM
thak you one more time whammy !
angiras
02-20-2003, 05:17 AM
I get an error on divFalse (I have tried with document.forms[0].divFalse.visibility = "show"; )
<head>
<script type="text/javascript">
function isdateString(somestring)
{
if (!/^(\d{1,2})\/(\d{1,2})\/(\d{2})$/.test(somestring))
{
document.divFalse.visibility = "show";
}
}
</script>
</head>
<body>
<form id="example" action="any">
<input type="text" onchange="isdateString(this.value)" /><div id="divFalse" style="visibility:hidden">false</div>
</form>
</body>
thank you
whammy
02-20-2003, 11:29 PM
Depending on what browser you're targeting, isn't that document.all.divFalse or document.getElementById('divFalse') ?
angiras
02-21-2003, 03:57 AM
now I get no error but the div don't show
<?xml version="1.0" encoding="iso-8859-1"?>
<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
<head>
<script type="text/javascript">
function isdateString(somestring)
{
if (!/^(\d{1,2})\/(\d{1,2})\/(\d{2})$/.test(somestring))
{
//document.all.divFalse= "show";
document.getElementById('divFalse').visibility = "show";
}
}
</script>
</head>
<body>
<form id="example" action="any">
<input type="text" onblur="isdateString(this.value)" /><div id="divFalse" style="visibility:hidden">false</div>
<br />
<input type="text" value="test" />
</form>
</body>
</html>
do you know what is missing ?
thank you
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.