Solved

Matching only numbers

Posted on 1998-11-17
7
227 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

930 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now