Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if Perl value is alpha or numeric 1

Status
Not open for further replies.

kb0rhe

Technical User
Dec 25, 2006
16
US
I have a value and I want to know if it is a numeric value.

There isn't anything to test a value if it is truly numeric. Nothing is jumping out at me. I have been looking online for a while.

Douglas

 
numeric is harder to check than for simple digits:

some ways that might work:

Code:
if (/\D/) {
   print "there is something that is not a digit";
}

Code:
if (/^\d+$/) {
   print "there are only digits in this thing so it's numeric.";
}

Code:
if (/\d/ && /^-?\d*\.?\d*$/) {
   print "an integer, negative number, or a decimal but not some other type of numeric value";
}

more ways to check here:







- Kevin, perl coder unexceptional!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top