473,666 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Percentage validation in a textfield.

6 New Member
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 5789
gits
5,390 Recognized Expert Moderator Expert
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
MRamaLakshmi
6 New Member
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.leng th == 0 || obj.value.lengt h == 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.leng th == 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.leng th == 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.ind exOf(".") != -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.leng th == 4 )
{
if ((obj.value.ind exOf(".") != -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="retu rn check(event.key Code , 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
1434
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 about this. Thanks.
5
1623
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: ", popup_menu(-name=>'myOption', -values=>), p, "URL of page to be changed: ", textfield(-name=>'urlToBeChanged',
1
1081
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 anybody help me with this?
1
1444
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. 1. for a text field if for example a user hits the space bar and then types the information with the validation i have the code ignores those initial spaces but actually these are spaces i need to insert these values in a database so these spaces...
3
304
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 Textboxes(1,2,3,4) should be mandatory and rest of the textboxes should not be mandatory. Kindly help me out..
2
1360
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
1507
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
3019
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. <form action="" method="get"> <div align="center"> <table border="0" cellspacing="0" cellpadding="0">
7
11323
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 field be highlighted with say border:red; using php or javascript needs to be used. i am asking this bcos i am not using javascript for validation purpose in this form.
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8863
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8780
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6189
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.