User talk:Tim.Landscheidt/Template:IsNumber

Latest comment: 16 years ago by Splarka in topic 14034

14034

edit

Per 14034#c5, the problem is, what you might consider shortcomings. Would IsNumber be used to validate input for #expr and #ifexpr? If so, that is what #iferror does (rather, it checks if all input was valid after the fact).

If however you wish to validate input for another reason, then what exactly are your requirements? I mean, 123,456,789 might be considered a valid number, but not according to #expr (nor almost any output of {{formatnum}}). And should exponent shorthand such as 5E+10 be? It is according to #expr. In [1], 22.12.2007 returns true of course, because #expr is able to resolve it as 22.12 ... 98765432109876543210 fails an ifeq because it is modified to 9.87654321099E+19, likewise 5E+10 becomes 50000000000. #iferror should work for all valid #expr input, with the shortcoming that it also resolves expressions.

But, to put it another way, which of these should return true for #ifnumber?

12345
1‮2345‭
123 45
123E+45
123 E+45
123E+ 45
123,456,789
123.456.789
123,456.78
123.456,78
 12345
12345 
-12345
- 12345
+12345
+ 12345
.012345
0.012345
123 + 45
123 - 45
123 ^ 45
123 % 45
123 mod 45

Splarka 21:01, 8 May 2008 (UTC)Reply

I don't know how you achieved the the first line/two lines so I will ignore it for a moment. I would like to have the following to test positive: "123456.789", " 12345", "12345", "-12345", "- 12345", "+12345", "+ 12345" and "0.012345". If "123E+45", "123E+ 45" and ".012345" would test positive as well, I could live with that. Or, in a Perlish regex, my basic pattern would be "\s*([-+]\s*)?\d+(\.\d+)?\s*". As stated, my goal is to prevent the editor from supplying pseudo-ranges (123-45) and similar errors hard to detect. Tim Landscheidt 23:22, 8 May 2008 (UTC)Reply
For the second line I was using some directional unicode overrides. Anyway, it does sound like #iferror will not satisfy your requirements for #ifnumber, but the rest of your requested functions could be done good enough with expr/if/ifeq/iferror? I mean, my ifintenger will still show an integer for 15.5 + .5, but that is much less likely to be a problem, IMHO. Splarka 00:24, 10 May 2008 (UTC)Reply
Return to the user page of "Tim.Landscheidt/Template:IsNumber".