hcrosex3
09-26-2012, 08:40 PM
I am trying to have my form include these two boxes.
One that requires 5 digit numeric input
and another that requires the first letter to be capitalized. The capitalization is working. But im not sure how in reqexp to require the the numeric digits be = to 5 . As well as for some reason the on blur is not working. Any Suggestions?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function validate() {
var the_input = document.getElementById('userName').value;
if (!the_input.match(/^[A-Z]$/)) {
alert('Your username must begin with a capital letter.');
return false;
} else {
return true;
}
}
function zip() {
var the_input = document.getElementById('zip').value;
if (!the_input(/^[A-Z]$/)) {
alert('You can only use numbers');
return false;
} else {
alert('You can only use numbers!!!');
return true;
}
}
</script>
</head>
<body>
<form action="test" method="get" name="logOn">
First Name:<br />
<input type="text" name="userName" id="userName" onblur="validate()" size="25" /><br />
Zipcode:<br />
<input type="text" name="zip" id="zip" onblur="zip()" size="25" /><br />
</form>
</body>
</html>
One that requires 5 digit numeric input
and another that requires the first letter to be capitalized. The capitalization is working. But im not sure how in reqexp to require the the numeric digits be = to 5 . As well as for some reason the on blur is not working. Any Suggestions?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function validate() {
var the_input = document.getElementById('userName').value;
if (!the_input.match(/^[A-Z]$/)) {
alert('Your username must begin with a capital letter.');
return false;
} else {
return true;
}
}
function zip() {
var the_input = document.getElementById('zip').value;
if (!the_input(/^[A-Z]$/)) {
alert('You can only use numbers');
return false;
} else {
alert('You can only use numbers!!!');
return true;
}
}
</script>
</head>
<body>
<form action="test" method="get" name="logOn">
First Name:<br />
<input type="text" name="userName" id="userName" onblur="validate()" size="25" /><br />
Zipcode:<br />
<input type="text" name="zip" id="zip" onblur="zip()" size="25" /><br />
</form>
</body>
</html>