Solved

Matching only numbers

Posted on 1998-11-17
7
254 Views
Last Modified: 2010-03-04
What is the pattern to match only numbers
ie;
a$ = "Yes" if(b$ contains only numbers);
0
Comment
Question by:Lee5
7 Comments
 
LVL 7

Accepted Solution

by:
HalldorG earned 50 total points
ID: 1206260
if ( $b =~ m/^[0-9]*$/g  )
 {$a='yes';}else {$b='no';}

0
 
LVL 4

Expert Comment

by:martinag
ID: 1206261
$a = 'Yes' if $b =~ m/^\d*$/g;

Martin
0
 
LVL 4

Expert Comment

by:martinag
ID: 1206262
Actually, that will treat an empty string as a number. If you don't want that, simply replace * with +.

Martin
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:b2pi
ID: 1206263
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
 
LVL 4

Expert Comment

by:martinag
ID: 1206264
>> FMTYEWTK
What would that be in plain english?

Martin
0
 

Author Comment

by:Lee5
ID: 1206265
Also thanks to b2pi and martinag
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1206266
Far More Than You Ever Wanted To Know

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl for loop for 2000 ms 7 109
Removing file extension within a file. 4 103
Perl string replace for refred url 9 70
Perl File::Find alternative 1 86
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question