473,372 Members | 989 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,372 software developers and data experts.

are "07" and "08" really all that different?

I have a web page. It uses JavaScript to test the user's input
before sending it to the server. It frequently tests using isNaN() with
some very interesting results.

The statements in question test values from text boxes using isNaN() and
also checking if they are still the same after parseInt or parseFloat
are performed on them. The second test is because isNaN() will return
false (is a number) for the string "3a".

The curious behavior is that when I enter the string "07" (or any value
less), it returns a number as it should. If I enter the string "08" or
"09", it acts as though I'd entered a non-digit.

I think maybe this whole problem could be solved by using regular
expressions instead of isNaN. I read some dox on RegEx, but didn't
understand much of it. Please help.

To see it, go to
http://ffej2ffej.com/re/start.php

log on as driver 236 with the password 236 then insert new data. Try
"07" and "08" in any of the text boxes and you'll see what I mean when
you try to save. Of course you can see all the javascript by viewing
the source of the frame.
Jul 23 '05 #1
5 1149
*Jeff Sandler* wrote in comp.lang.javascript:
[snip]
The curious behavior is that when I enter the string "07" (or any value
less), it returns a number as it should. If I enter the string "08" or
"09", it acts as though I'd entered a non-digit.

[snip]

See the following regarding the optional radix parameter:
http://msdn.microsoft.com/library/en...thparseint.asp

More info at: http://jibbering.com/faq/#FAQ4_12
--
Andrew Urquhart
- FAQ: http://www.jibbering.com/faq/
- Archive: http://www.google.com/groups?q=comp.lang.javascript
- Contact me: http://andrewu.co.uk/contact/
Jul 23 '05 #2
On Mon, 30 Aug 2004 12:32:31 -0700, Jeff Sandler
<ff*******@dslextreme.com> wrote:
I have a web page. It uses JavaScript to test the user's input before
sending it to the server. It frequently tests using isNaN() with some
very interesting results.
You should check formatted input with regular expressions.

[snip]
The curious behavior is that when I enter the string "07" (or any value
less), it returns a number as it should. If I enter the string "08" or
"09", it acts as though I'd entered a non-digit.
This issue is covered in the FAQ.

<URL:http://jibbering.com/faq/>
I think maybe this whole problem could be solved by using regular
expressions instead of isNaN. I read some dox on RegEx, but didn't
understand much of it. Please help.


The URI below might be of some help. If you need specific help, don't
hesitate to ask.

<URL:http://www.merlyn.demon.co.uk/js-valid.htm>

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3
Jeff Sandler wrote:
I have a web page. It uses JavaScript to test the user's input
before sending it to the server. It frequently tests using isNaN() with
some very interesting results.

The statements in question test values from text boxes using isNaN() and
also checking if they are still the same after parseInt or parseFloat
are performed on them. The second test is because isNaN() will return
false (is a number) for the string "3a".
You should test isNaN(entry) before you try to parseInt(entry,radix), if
at all.
You need to supply the radix (10, for decimal numbers.)
077 is interpreted as base 8, for example.
You will be better served using a regex to verify a Number, or you could
test an assignment:
if(entry*1){//entry is a Number}

Mick

The curious behavior is that when I enter the string "07" (or any value
less), it returns a number as it should. If I enter the string "08" or
"09", it acts as though I'd entered a non-digit.

I think maybe this whole problem could be solved by using regular
expressions instead of isNaN. I read some dox on RegEx, but didn't
understand much of it. Please help.

To see it, go to
http://ffej2ffej.com/re/start.php

log on as driver 236 with the password 236 then insert new data. Try
"07" and "08" in any of the text boxes and you'll see what I mean when
you try to save. Of course you can see all the javascript by viewing
the source of the frame.

Jul 23 '05 #4
JRS: In article <YL********************@twister.nyroc.rr.com>, dated
Mon, 30 Aug 2004 20:05:12, seen in news:comp.lang.javascript, Mick White
<mw******@BOGUSrochester.rr.com> posted :
or you could
test an assignment:
if(entry*1){//entry is a Number}


Provided that zero is not a valid entry.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 23 '05 #5
Dr John Stockton wrote:
JRS: In article <YL********************@twister.nyroc.rr.com>, dated
Mon, 30 Aug 2004 20:05:12, seen in news:comp.lang.javascript, Mick White
<mw******@BOGUSrochester.rr.com> posted :

or you could
test an assignment:
if(entry*1){//entry is a Number}

Provided that zero is not a valid entry.

I never did quite grasp the concept of zero....
Yes, you make a good point, although in this case the assigment test
suffices.
Mick
Jul 23 '05 #6

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

Similar topics

13
by: Adam | last post by:
My "C:\" is getting full. What's the best way to install "wxWindows" without taking up 115 MB from my "C:\" ? Why do the following: MS Visual Studio, wxWindows, Borland C++, Stingray...
8
by: Paul T. Rong | last post by:
I used "between and " in a query as a criteria to a field called ShipDate. Very strange, in the case between 1.10.2003 and 31.10.2003, then the records from 31.10.2003 don't show up. I have to...
26
by: Chris Potter | last post by:
Hello everyone. I am taking my first course in C and in one of my assignments i need to print out an array that could have anywhere from 0 to 100 positive integers in it (a negative integer is...
12
by: baumann | last post by:
hi all, printf("%c",b) doesn't work properly. #include <stdio.h> int a , b; char d, e; char * p; float f; int main(int argc, char* argv) {
1
by: Alex Chan | last post by:
Hi Group, I have written a window service wtih SAP.NET Connector which is to fulfil request from SAP client. SAP client will call a function exposed by my window service that has a big "out"...
18
by: Martin Jørgensen | last post by:
Hi, Today I got a really strange problem... I've made myself a data-file and I read in data from that file.... When I read something like this line: 03 04 05, 00 04 01, 05 03 07, 08 03...
21
by: Owen Zhang | last post by:
What is the best way to implement "tail -f" in C or C++ and higher performance compared to either unix shell command "tail -f" or perl File::Tail ? Any suggestion appreciated. Thanks.
7
by: ankitoshniwal | last post by:
Hello, I have been having this problem for the whole day today, so even after i googled for the solution i was not able to get one, so i had to post to this forum. I had checked the solutions...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.