Check for valid hex value
Author Message
Check for valid hex value

How can I check that a value entered is a valid hex value?  The entry is
up to 16 hex digits long and I need to ensure it only contains the
characters 0123456789abcdf.

Thanks for the help,
Ed

Tue, 17 Feb 2004 18:02:07 GMT
Check for valid hex value

Quote:
>How can I check that a value entered is a valid hex value?  The entry is
>up to 16 hex digits long and I need to ensure it only contains the
>characters 0123456789abcdf.

if (\$value =~ /[^0-9a-f]/) {
# it contains a bad character
} elsif (length(\$value) > 16) {
# it is too long
} else {
# it's good
}

rd
(\$p{\$_})&6];\$p{\$_}=/ ^\$P/ix?\$P:close\$_}keys%p}p;p;p;p;p;map{\$p{\$_}=~/^[P.]/&&
close\$_}%p;wait until\$?;map{/^r/&&<\$_>}%p;\$_=\$d[\$q];sleep rand(2)if/\S/;print

Tue, 17 Feb 2004 18:16:13 GMT
Check for valid hex value

Quote:
>How can I check that a value entered is a valid hex value?  The entry is
>up to 16 hex digits long and I need to ensure it only contains the
>characters 0123456789abcdf.

this looks like a good problem for a regexp.

see perldoc perlre
perldoc perlop

let us know if you have problems with it

gnari

Tue, 17 Feb 2004 23:16:36 GMT
Check for valid hex value

Quote:
> How can I check that a value entered is a valid hex value?

<snip>
map { print "\$_: invalid\n" unless eval "0x\$_" } qw(
8a
4711
gh
b
9g
);
</snip>

errors.

Quote:
> Thanks for the help,
> Ed

Heinz

Wed, 18 Feb 2004 23:05:06 GMT

 Page 1 of 1 [ 4 post ]

Relevant Pages