Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: only want numerics in field

by bigj (Monk)
on Apr 21, 2014 at 15:52 UTC ( #1083034=note: print w/replies, xml ) Need Help??

in reply to only want numerics in field

Your formatting is pretty much screwed. However, if you want to check a field for should contain only numeric values like 12345.67 or 0 or 0.00 or -123.78, the usual regexp to do that would be like:
/^[+-]\d+(?:\.\d+)?$/ # or if you want either no decimals or exactly 2 decimals /^[+-]\d+(?:\.\d\d)?$/
But I think, if I look to your code, you seem to have more than just a decimal number inside. You might also take a look to modules like Regexp::Common. Most of us will make a mistake here or their when build Regexps, the good thing common things is that we aren't the first one doing them :-)

Janek Schleicher

Replies are listed 'Best First'.
Re^2: only want numerics in field
by Limbic~Region (Chancellor) on Apr 21, 2014 at 16:09 UTC
    Your regex will indicate that .25 is not a number. You also require a leading sign [+-]. I realize that defintion of "what is numeric" is sorely lacking by the OP but I wanted to point this out to anyone who may come along later.

    Cheers - L~R

      Just one more reason to not reinvent the wheel :-) You're of course right.

      Janek Schleicher

Re^2: only want numerics in field
by newby2perl (Initiate) on Apr 21, 2014 at 16:40 UTC

    yes it will be an amount with only 2 places after the decimal.

      it should allow - for negative numbers

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1083034]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2018-06-18 11:56 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (109 votes). Check out past polls.