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
Medium Priority
269 Views
What is the pattern to match only numbers
ie;
a\$ = "Yes" if(b\$ contains only numbers);
0
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

LVL 7

Accepted Solution

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

0

LVL 4

Expert Comment

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

Martin
0

LVL 4

Expert Comment

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

Martin
0

LVL 5

Expert Comment

ID: 1206263
Furthermore, what it the number is

7.0e6

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

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

Martin
0

Author Comment

ID: 1206265
Also thanks to b2pi and martinag
0

LVL 5

Expert Comment

ID: 1206266
Far More Than You Ever Wanted To Know

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

## Featured Post

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
###### Suggested Courses
Course of the Month5 days, 9 hours left to enroll