> Strictly development-related issues should be discussed on the dev group:
I considered doing that, but frankly I hesitated because I have no idea what many of the posts over there are about or what their norms are, and I had a feeling that basic, not-TW-specific questions might not be considered appropriate there either. > Therefore, even though regular expressions are often overused, it seems > that might be the safest choice here: > if(testStr.search(/^\d+$/) != -1) { ... } > It may be more stable over platforms... but I tend to resist a character-scan approach. Once you open one up enough to allow decimals, signs etc., it also tends to pass things like "------", "....." and "834.234.343" which won't convert, or shouldn't, and code to tighten a character-scan approach beyond that level tends to get very elaborate and error-prone. I'm not equipped (or, frankly, probably motivated) to test on a slew of platforms. If this is getting near the edge, it might be safer for me to rework around the limitations of parseInt() etc. Thanks. On May 23, 2:56 pm, FND <f...@gmx.net> wrote: > N.B.: > Strictly development-related issues should be discussed on the dev group: > http://groups.google.com/group/TiddlyWikiDev/ > > > 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 > > This seems odd indeed - though apparently that's how it's supposed to > be:https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global... > > > implicit conversion seems to fail if it can't convert the entire > > string, and can be exploited > > Note that different browsers might react differently, so you should test > for this quirk in Firefox, IE 6-8, WebKit (Safari, Chrome) and Opera - > not to mention mobile browsers... (Welcome to the beautiful world of web > development.) > > Therefore, even though regular expressions are often overused, it seems > that might be the safest choice here: > if(testStr.search(/^\d+$/) != -1) { ... } > > HTH. > > -- F. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---