Solved

Matching only numbers

Posted on 1998-11-17
7
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl - Mawk 2 110
Reading fields from the text file. 4 106
delete query using perl dbi 3 122
Transforming a Soap message to a simple xml message! 10 168
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…
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…

751 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