Matching only numbers

What is the pattern to match only numbers
ie;
a$ = "Yes" if(b$ contains only numbers);
Lee5Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
HalldorGConnect With a Mentor Commented:
if ( $b =~ m/^[0-9]*$/g  )
 {$a='yes';}else {$b='no';}

0
 
martinagCommented:
$a = 'Yes' if $b =~ m/^\d*$/g;

Martin
0
 
martinagCommented:
Actually, that will treat an empty string as a number. If you don't want that, simply replace * with +.

Martin
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
b2piCommented:
Furthermore, what it the number is

7.0e6

There's a FMTYEWTK about this on the perl.com site. I generallly do

sub IsNumber {
    local($^W) = 0;
    my($a) = shift;
    return 0 if !defined($a);
    $a = s/^\s+|\s+$//;
    return 0 if $a eq '';
    return $a == $a + 0;
}

    return $a == $a + 0;

0
 
martinagCommented:
>> FMTYEWTK
What would that be in plain english?

Martin
0
 
Lee5Author Commented:
Also thanks to b2pi and martinag
0
 
b2piCommented:
Far More Than You Ever Wanted To Know

(Like FAQ, but Not so Frequent :))
0
All Courses

From novice to tech pro — start learning today.