473,651 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

field validation needs to accept decimal values -- how please?

I need this function to accept decimal values (e.g., 2.5 ok, not just
whole numbers between 1 and 5).

I can't find this answer...

thanks, kat

*************** ************
function ValidateSave(fo rmRef,fieldName ,min,max)
{
var formField = formRef.element s[fieldName];

if((parseInt(fo rmField.value) != formField.value ) || formField.value <
min || formField.value > max)
{
alert("The entry must be between " +min+ " and " +max+ ".");
formField.focus ();
formField.selec t();
return false;
}
....else code left out
Jul 20 '05 #1
6 11003

"KathyB" <Ka**********@a ttbi.com> schreef in bericht
news:75******** *************** ***@posting.goo gle.com...
I need this function to accept decimal values (e.g., 2.5 ok, not just
whole numbers between 1 and 5).


I would use a regular expression for this, e.g.:

var figure = '1.1';
var reg = /^\d+(\.\d+)?$/;

alert(reg.test( figure)); // alerts true

With this, your function might look like this:

function ValidateSave(fo rmRef,fieldName ,min,max) {
var formField = formRef.element s[fieldName];
if (!/^\d+(\.\d+)?$/.test(formField )) {
alert('Invalid entry!');
formField.focus ();
formField.selec t();
return false;
}

if (formField.valu e < min || formField.value > max) {
alert("The entry must be between " +min+ " and " +max+ ".");
formField.focus ();
formField.selec t();
return false;
}
}
JW

Jul 20 '05 #2

"Janwillem Borleffs" <jw@jwscripts.c om> schreef in bericht
news:3f******** *************** @news.euronet.n l...

I would use a regular expression for this, e.g.:


Made an error in my code, please use the following:

function ValidateSave(fo rmRef,fieldName ,min,max) {
var formField = formRef.element s[fieldName];
if (!/^\d+(\.\d+)?$/.test(formField .value)) {
alert('Invalid entry!');
formField.focus ();
formField.selec t();
return false;
}

if (formField.valu e < min || formField.value > max) {
alert("The entry must be between " +min+ " and " +max+ ".");
formField.focus ();
formField.selec t();
return false;
}
}
JW

Jul 20 '05 #3
JW, thanks so much! That works great. I've seen reg expressions
before...but clearly need to go study them a bit.

Thanks again.

Kathy

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4
Hi again, JW. For some reason, I'm getting an error on this
function...look s ok to me, but the parser (Xselerator) says I'm missing
a "[" or a "(" -- can't tell which. Doesn't give me the exact line, but
when I remove this function, I don't get the error.

Thanks,

Kathy

function ValidateSave(fo rmRef,fieldName ,min,max)
{
var formField = formRef.element s[fieldName];
if (!/^\d+(\.\d+)?$/.test(formField .value)) {
alert('Invalid entry! Please try again.');
formField.focus ();
formField.selec t();
return false;
}
if formField.value < min || formField.value > max {
alert("The entry must be between " +min+ " and " +max+ ".");
formField.focus ();
formField.selec t();
return false;
}
else
{
varScroll = document.body.s crollTop;
document.cookie ="position="+va rScroll;
return confirm("You are about to enter: " +formField.valu e+ " --
click OK to proceed.");
}
}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5

"Kathy Burke" <ka**********@a ttbi.com> schreef in bericht
news:3f******** *************@n ews.frii.net...

function ValidateSave(fo rmRef,fieldName ,min,max)
{ ..... }
if formField.value < min || formField.value > max {


Hi Kathy,

The if statement above is where the problem is, it should read:

if (formField.valu e < min || formField.value > max) {
JW

Jul 20 '05 #6
Thanks again! Guess I was too tired.

Kathy

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2027
by: Calan | last post by:
I have a server-side ASP script that dynamically creates an input form from a database table. The table contains a field name, the table where values are stored, type of input control, value for a label, etc. What I need to do is create a JS validation routine that will check each control for valid input, regardless of what the control name is. If it is a "select", it needs to verify the index is > 1. If it is an "input", it needs to...
8
15484
by: SAN CAZIANO | last post by:
i have to do in the onkeypress or in onchange the float (real) field validation I try something: function ValidaCampo(nomeCampo,TotInteri,TotDecimali) { DecimalPos=NomeCampo.value.Indexof(','); Lungh=TotInteri+TotDecimali+1; //sum the ineger + decimal + decimal separator
2
10415
by: Doslil | last post by:
I am trying to validate the fields in my database.I have already validated the fields to check for not null.Here is what I have written for Numeric and text field. Private Function EENUM() On Error GoTo EENUMErr If IsNull(Me.EmployeesID) Or Me.EmployeesID = "" Or Me.EmployeesID < 0 Then MsgBox "Employee Number Cannot Be Left Blank", vbOKOnly, "Employee Number"
1
1466
by: Barnoit | last post by:
I'm sure this is very easy, but I know very little about access. I'm trying to add a validation rule to my textbox to only accept alphnumeric chars. From the alpha side, I tried Like "" , which accepts a single char. So I tried to add an asterisk ie. Like "*", but that now accepts any char. How do you apply the rule to each character entered, if you don't know the length of the input string beforehand? Thanks in advance.
8
1556
by: Tony Williams | last post by:
I have a form where the user inputs a series of figures into a number of controls. After they've input the total (they don't want the program to create the total) there is a check to make sure the total of the controls equals the totals they've input. Here is the code in the Before Update property: Private Sub txtAdvTot_BeforeUpdate(Cancel As Integer) If ( + + + + + + ) <> Then If MsgBox(" Column 1 does not add up" & vbCrLf & "It...
4
2579
by: bienwell | last post by:
Hi, I have a problem and really need your help. In my web page ASPX, I have some text fields to accept data from users. I did form validation like this : <td class="dataTD" style="HEIGHT: 30px" width="100"> <asp:TextBox id="txtFUEL_ISSUED1" style="Z-INDEX: 100; POSITION: absolute" runat="server" Width="107px" BorderColor="Transparent" autoPostback="true"
27
35923
by: code_wrong | last post by:
Visual Basic (not dot net) what is the best way to check the User has entered an integer into an InputBox? isNumeric() checks for a numeric value .. but does not notify of numbers with decimal places inputBox returns a string so I could check for decimal point??? this seems like overkill The value returned can be asigned into an Integer type and then a Single
7
3802
by: Chuck Anderson | last post by:
I'm pretty much a JavaScript novice. I'm good at learning by example and changing those examples to suit my needs. That said .... ..... I have some select fields in a form I created for a database search that I am unable to figure out how to access. (The search is implemented in Php/MySQL.) The user enters search values for: name, address1, city, .... etc., ..... and for each of these they also select whether the search should...
2
3115
by: jmarr02s | last post by:
I have a field with a Number data type, Double field size and Auto decimal places. The values of this field should have 3 digits to the right of the decimal place. For example, 123456.123 I have used the following expression in my query to ensure all 3 decimal places show to the right of the decimal, Expr2:Format(,"0.000")
0
8352
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
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8802
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
8697
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...
0
8579
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
6158
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
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2699
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
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.