Solved

Matching only numbers

Posted on 1998-11-17
7
219 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

21 Experts available now in Live!

Get 1:1 Help Now