Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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 content...it 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 :-)

Greetings,
Janek Schleicher


Comment on Re: only want numerics in field
Download Code
Re^2: only want numerics in field
by Limbic~Region (Chancellor) on Apr 21, 2014 at 16:09 UTC
    bigj,
    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.

      Greetings,
      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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1083034]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-12-18 22:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (67 votes), past polls