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 davido (Archbishop)
on Apr 21, 2014 at 16:37 UTC ( #1083041=note: print w/ replies, xml ) Need Help??


in reply to only want numerics in field

You could use Regexp::Common's "number" extension to detect reals, which is what you seem to be seeking:

if( $string =~ /^$RE{num}{real}$/ ) { print "Match!\n"; } else { print "Reject!\n"; }

You don't want to invent this yourself. Just look at the regular expression that $RE{num}{real} contains:

perl -MRegexp::Common=number -E 'say $RE{num}{real}' (?:(?i)(?:[-+]?)(?:(?=[.]?[0123456789])(?:[0123456789]*)(?:(?:[.])(?:[ +0123456789]{0,}))?)(?:(?:[E])(?:(?:[-+]?)(?:[0123456789]+))|))

...better off using a solution from Regexp::Common, or the looks_like_number() utility Limbic~Region suggested, or both.


Dave


Comment on Re: only want numerics in field
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2014-12-18 15:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (58 votes), past polls