textbox form validation

A

Anonymous

Guest
Hi All,

I just need a simple help here coz I’m noon in javascript . I don’t find any of this problem in this forums so I make this thread...
How to limit our textbox to max number like 0-20,000? I’ve search but still cannot find the solution...
Please help.

Thanks.
 
if you just want to restrict user by inputting larger value than you want then use

<input type="text" maxlength="255">
 
Hi there,

Sorry for not explain you clearly but I need to make user insert the number exact 0-20000 in text not the number of digit that can be insert. The maxlength function just limits the max digit to be inserted to the textbox. Tq anyway
 
Hi there!

I have used this code for my website, and it works just fine, but I don't know if it meets your requirement or not.

Here is the code

Code:
<html>
<head>
<title>Limit Number</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
< script >
function setmaxnumber(txtnumber,minnumber,maxnumber){
	if(!parseFloat(txtnumber.value)){
		txtnumber.value = "";
	}
	else if(parseFloat(txtnumber.value)<minnumber){
		txtnumber.value = ""+minnumber+"";
	}
	else if(parseFloat(txtnumber.value)>maxnumber){
		txtnumber.value = ""+maxnumber+"";
	}
}
</ script >
</head>
<body>
<form action="limitnumber.php" method="post">
	<input type="text" name="txtinput" id="txtinput" maxlength="20" onKeyDown="setmaxnumber(this,0,20000);" onKeyUp="setmaxnumber(this,0,20000);" />
</form>
</body>
</html>

Makara Kao
 
I’ve tested it and it’s worked!! Tq Makara Kao. I owe u..
 
Back
Top