Noob here.

In testing a (user-entered) string to see if it's (potentially)
numeric, somewhat to my surprise the string methods parseInt() and
parseFloat() will return a number if the first part of the string
converts successfully, ignoring trailing non-numeric characters (and
not making an index availalbe of where they quit converting the
string). The function isNaN() behaves the same way.

That's not always what's desired. Curiously, then (at least to me),
implicit conversion seems to fail if it can't convert the entire
string, and can be exploited.

if(testStr==0||testStr/1)
   proceed on success path...
else
   proceed on failure path...

Seems to work (success) with positive, negative, integers, decimals
and zero, leading or trailing spaces and leading zeros, and still
fails trailing non-numeric characters

Is there a downside I'm not seeing?  Is this the sort of behavior
that's likely to morph in different browsers?

Thanks.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to TiddlyWiki@googlegroups.com
To unsubscribe from this group, send email to 
tiddlywiki+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/TiddlyWiki?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to