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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regex to check its all digits 3

Status
Not open for further replies.

serpento

Programmer
Jun 16, 2002
92
GB
I'm only a beginner at using regular expressions, and would like to know how to use one to see if $variable contains only digits or not. I.e. I want a statement that returns false if $variable contains any character other than a digit.

Any help would be very much appreciated.

-Ed ;-)

________________________________
Destiny is not a matter of chance; it is a matter of choice.
 
\D is the regex character class for all characters except digits:-

if ($data =~ /\D/) {
print "FALSE - data other than numbers found\n";
}
else {
print "TRUE - only numbers found\n";
}


Duncan
 
Thank you all for your help, you have all solved my problem perfectly! Have a star each.

-Ed ;-)

________________________________
Destiny is not a matter of chance; it is a matter of choice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top