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      
        deadbeef
        9g
);
</snip>


errors.

Quote:
> Thanks for the help,
> Ed

Heinz


Wed, 18 Feb 2004 23:05:06 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Pringing Hex Values as Hex

2. Creating ascii values from hex value in a variable

3. Check for valid perl regex

4. Checking if a url is valid

5. How do I check for a valid URL

6. checking if mail address is valid

7. checking for a valid date-time

8. Checking if URL is valid/exist using PERL

9. A Script for checking emails valid?

10. Checking for valid Email...

11. check for valid e-mail address

12. How to check if an email address is valid

 

 
Powered by phpBB® Forum Software