PDA

View Full Version : Valid Text Field


Retard-3000
05-29-2008, 02:46 PM
Hey, i dont know wether this is javascript or not but i was wondering what code would i use to check whether a text input field had more than 3 characters and less then 10. i thought about using variables but dont know how, this is initially how i tried it.

<html>
<head>
<title>Javascript</title>
<script type="text/javascript">
function usercheck()
if(text1 <somethingtosaylessthen3characters)
{
alert("Your Username Must Be More Than 3 Characters Long");
}
else if(<somethingtosaylessthen10characters)
{
alert("Thank You")
}
</script>
</head>
<body>
<input type="text" name="text1"><input type="button" value="Check" onclick="usercheck()">
</body>
</html>

i dont know how to explain it any better but any help is appreciated thanks

rangana
05-30-2008, 12:35 AM
See if this code helps:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Javascript</title>
<script type="text/javascript">
window.onload=function()
{
document.getElementById('toggle').onclick=function()
{
var input=document.getElementById('inp');
if ((input.value.length<3)||(input.value.length>10))
alert('Username should\'nt get beyond 3 characters \nand should\'nt go above 10 characters long');
else
alert('Thank You');
}
}
</script>
</head>
<body>
<input type="text" name="text1" id="inp">
<input type="button" value="Check" id="toggle">
</body>
</html>

Retard-3000
05-30-2008, 06:50 AM
thanx. that helped alot

rangana
05-30-2008, 06:59 AM
No problem, glad to help :)