Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Matching only numbers

Posted on 1998-11-17
7
Medium Priority
?
269 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 200 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
Industry Leaders: 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Six Sigma Control Plans

660 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