Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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

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 rifling through the Monastery: (4)
As of 2016-10-01 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?






    Results (9 votes). Check out past polls.