checks to see if $input contains a digit anywhere in the string so that all of the following will match:$input =~ /\d/;
if you want to insure that the string contains only one digit in it you can do something like the following (it will be true as long as only one thing is a digit no more no less):21 dfjdfkfjd2 jf2kjf 9343kfd2
on the other hand if you want to make sure the only thing in $input is a single digit then the following will work:$input =~ /^\D*\d\D*$/;
which breaks down to finding the following pattern, the ^ anchors that the match starts at the start of the line, and the $ makes sure that the \d is the last thing in the line before the newline character(if it exists).$input =~ /^\d$/
-enlil
In reply to Re: Checking for single digit
by Enlil
in thread Checking for single digit
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |