Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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 drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2014-08-28 10:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (259 votes), past polls