Re: Numeric valication



My reply at end

Dr John Stockton wrote:
JRS: In article <uvz6RRqYGHA.4060@xxxxxxxxxxxxxxxxxxxx>, dated Tue,
18 Apr 2006 14:55:28 remote, seen in
news:microsoft.public.scripting.jscrip t, Trevor L.
<Trevor_L.?@Canberra.?> posted :

This is a topic I have just started to learn, and it should work
quite well here if you get the syntax correct

I thought this might work
if (/^\-?[0-9]|\.?/.test(vartotest)) == true

Before learning RegExps, one should learn Booleans. Part '== true' is
not necessary (and your final parenthesis should be at the end).

Moreover, the RegExp is wrong; it accepts any string EITHER
containing a minus followed by a digit OR containing a dot which
might not be there - in other words, AFAICS, *anything* apart from an
undefined vartotest (vartotest defined, but with value undefined,
passes OK).

Thanks, John

I can see the error in the if statement
It should be
if (condition)
OR
if (condition == true)

It wasn't so much that I didn't understand booleans. I knew that "== true"
was redundant - I put it there for clarity.
My error was that I misplaced the ')'

I will plead having an old day as my excuse. My JS knowldege is not
extensive (about 15 months worth, all picked up form the net) but as an
ex-programmer, I should have known/remebered enough to place the ')'
correctly ;-))

And thanks for pointing out the error in the regexp
So I guesss I shoud have written:
/^\-?[0-9]\.?/
BUT AFAICS, this accepts any string containing a leading minus which might
not be there, followed by a digit AND followed by a dot which might not be
there

However, the dot is in the wrong position.

So to further my knowledge of regexps, I will study your examples further.

Is this the correct interpratation of your OK1 = /^-?\d+(\.\d+)?$/.test(S)
any string which commences with a minus which might not be there, followed
by a digit 1 or more times, followed by a single dot and a digit 1 or more
times both of which might not be there but which must be at the end of the
string.

I take it that "compatible with IUPAP/SUNAMCO" means that this is some
standard definition of a number.
--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.auhanks,


.



Relevant Pages

  • Re: numeric sorting on a char field having a decimal
    ... We also need to know what to do if there's a second dot in the string, ... separates non-empty digit strings. ... sequence and the characters after the dot are in ascending numerical ...
    (comp.databases.informix)
  • Re: writing get_script as an external routine callable by C
    ... I _STRONGLY_ suggest to attend a Perl class or a self-study course where ... If you mean "begins with a digit" as you said above ... Case 2 matches if the beginning of the string is followed by 1 or more ... If you put the two Bushs together in their over seven years of their two ...
    (comp.lang.perl.misc)
  • Re: Code to check if a valid e-mail address was entered
    ... Function Valid_Email(E_Address As String) As Boolean ... ' Note that the part after the @ sign must contain at least one dot, ... ' at least one other character following it, ... Dim TString As String ...
    (microsoft.public.access.modulesdaovba)
  • Re: Sorted Fixed Length String
    ... >I have a String of Numerical Digits Created Using Concatenate. ... >The Strings could be from 6 Characters in Length to 11 Characters in ... >The Least Characters in a String with a Digit GREATER than 1 can ONLY be ... Dim str As String ...
    (microsoft.public.excel.programming)
  • Re: Pi as the Mother Number
    ... For example if we find our 100-digit string starting at the ... 37th digit of pi, we can just say, go to the 37th digit of pi and print the ... problem with using this principle to compress numbers is the problem of the ... Foundation of Mathematics, first to understand the difference between ...
    (sci.math)