By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,572 Members | 959 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,572 IT Pros & Developers. It's quick & easy.

Percentage validation in a textfield.

P: 6
Hi,

Do any body have validation script for a textfield which is a percentage field where i should be able to enter values between 0.0 to 100.0

if user tries to enter any other value it should not accept.It should not even allow the user to enter.

I am in a urgent requirement.
Please any body help me out from this.

Thanks,
Lakshmi.
Oct 30 '08 #1
Share this Question
Share on Google+
2 Replies


gits
Expert Mod 5K+
P: 5,325
please show what you have done so far ... we don't just provide solutions without seeing that you have tried something before ...

kind regards
MOD
Oct 30 '08 #2

P: 6
please show what you have done so far ... we don't just provide solutions without seeing that you have tried something before ...

kind regards
MOD
sure.
this is my code. Not yet completed. i felt like it is not a right way to handle it.

[HTML]<html>
<head>
<script type="text/javascript">
function check($char, obj){
if (obj.value > 100.0)
{
return false;
}
if (obj.value.length == 0 || obj.value.length == 1)
{
if(($char >= 48 && $char <= 57)||($char >= 96 && $char <= 105) || $char == 190 || $char == 8 || $char == 9 || $char == 46 || $char == 13 || $char == 9 || $char == 35 || $char == 36 || $char == 37 || $char == 39 || $char == 110)
{
return true;
}
}
else if (obj.value.length == 2 )
{
if ((obj.value > 10) && ($char == 110 || $char == 190 ||$char == 46 || $char == 8 || $char == 9 || $char == 37 || $char == 39 || $char == 35 || $char == 36))
{
return true;
}
else if ((obj.value == 10) && ( $char == 48 || $char == 96 || $char == 110 || $char == 190 ||$char == 46 || $char == 8 || $char == 9 || $char == 37 || $char == 39 || $char == 35 || $char == 36))
{
return true;
}
else if ((obj.value < 10) && (($char >= 48 && $char <= 57)||($char >= 96 && $char <= 105) || $char == 190 || $char == 8 || $char == 9 || $char == 46 || $char == 13 || $char == 9 || $char == 35 || $char == 36 || $char == 37 || $char == 39 || $char == 110))
{
return true;
}
else
{
return false;
}
}
else if (obj.value.length == 3 )
{
if ((obj.value == 100) && ($char == 110 || $char == 190 || $char == 46 || $char == 8 || $char == 37 || $char == 39 || $char == 35 || $char == 36))
{
return true;
}
else if ((obj.value.indexOf(".") != -1) && (($char >= 48 && $char <= 57)||($char >= 96 && $char <= 105) || $char == 190 || $char == 8 || $char == 9 || $char == 46 || $char == 13 || $char == 9 || $char == 35 || $char == 36 || $char == 37 || $char == 39 || $char == 110))
{
return true;
}
else
{
return false;
}
}
else if (obj.value.length == 4 )
{
if ((obj.value.indexOf(".") != -1) && (($char >= 48 && $char <= 57)||($char >= 96 && $char <= 105) || $char == 190 || $char == 8 || $char == 9 || $char == 46 || $char == 13 || $char == 9 || $char == 35 || $char == 36 || $char == 37 || $char == 39 || $char == 110))
{
return true;
}
else
{
return false;
}
}
else if (($char == 46 || $char == 8 || $char == 9 || $char == 37 || $char == 39 || $char == 35 || $char == 36))
{
return true;
}
else
{
return false;
}
}
</script>
</head>
<body>
<input type="text" maxlength=5 onkeydown="return check(event.keyCode , this);" />
</body>
</html>[/HTML]

thanks.
Oct 30 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.