Of course, once again I forgot to explain myself.
/^(+|-)?\d+$/ means:
/^ : Starting at the beginning of the variable
(+|-) : '+' or '-' (see next line)
? : Match zero or one of the above character
\d+ : Followed by one or more digits
$/ : Followed by the end of the variable
-----Original Message-----
From: Timothy Johnson
To: 'Shawn '; 'Donnie Jones '; '[EMAIL PROTECTED] '
Sent: 6/29/02 11:20 PM
Subject: RE: Check for integer
Except that their checking for an integer, so it's even simpler than
that.
if($scalar =~ /^(+|-)?\d+$/){
print "It's an integer!\n";
}
Will check for an integer, with or without a plus or minus sign.
-----Original Message-----
From: Shawn
To: Donnie Jones; [EMAIL PROTECTED]
Sent: 6/29/02 8:07 PM
Subject: Re: Check for integer
----- Original Message -----
From: "Donnie Jones" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, June 29, 2002 8:03 PM
Subject: Check for integer
> Hello,
Hello Donnie,
>
> I was wondering if anyone knows how someone can test the value held by
a variable in perl to see if it is an integer?
>
> My current project is using the perl DBI, and I was users to enter
data, but to make sure that they don't enter strings
> in integer fields...
You can check the input like this:
unless($string=~/^\d+(\.\d+)$/) {
error...
}
NOTE: This will not work for scientific notation, etc.
Shawn
>
>
> Please help.
>
> Thanks,
>
> --Donnie
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]