473,324 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Percentage validation in a textfield.

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
2 5772
gits
5,390 Expert Mod 4TB
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
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

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

Similar topics

2
by: juicy | last post by:
I want to do validation on a textfield value key in by user, but I do not have idea on what method I can use. Is it possible to do it on 'onblur' event? Please give some ideas or useful links...
5
by: jdserran | last post by:
i need help, this is my code for my form: print header; print start_html('Assignment 2'), start_form(-action=>'lwpmsample.pl',-method=>'POST'), "Option: ",...
1
by: mikaint | last post by:
I need a validation script for a form to perform 2 actions: 1. if a checkbox is checked, then a relevant textfield should contain some input 2. don't allow commas (,) inside that textfield Can...
1
by: runway27 | last post by:
i have a registration page where a user fills up a form such as username, first name, phone number etc. i need to do a validation for the following fields. any help will be greatly appreciated. ...
3
by: sanju | last post by:
Dear All, i have 10 textboxes on a form, I require the following validation 1) if i fill the textbox in between(say 5th), then all textboxes before that should be mandatory,ie...
2
by: sukatoa | last post by:
I am a newbie on JavaScript.... I would like to know about what's wrong in my code below: <html> <head> <title>Text Example</title> </head> <body>
1
by: lijiunni | last post by:
how will i validate textfield in jsp using javascript..........and also i have to set focus back to textfield if the validation result is wrong......i need an example coding
4
by: pureadrenaline | last post by:
Hey Guys, Please could anyone help me out with the following form I need to create a validation on the email field only if the user checked the radio button named Email. Thanks in advance. ...
7
pradeepjain
by: pradeepjain | last post by:
hii. i am developing a new form for which validation is done using php , so the error text gets displayed also,I wanted to make a improvement for form. i.e can the textfield for which validation...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.