#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    27
    Rep Power
    0
    I have a user form that instructs the user to input a hex string (ie. 1A:334:5F:CC)
    I need to validate that each character entered is a valid hex character 1-9 A-F.
    Any ideas of how to do this effeciently?
    My current code breaks the string into individual characters and checks them in a foreach loop with the hex values in an array...this seems to be ineffective.

    Thanks
  2. #2
  3. No Profile Picture
    ledjon
    Guest
    Devshed Newbie (0 - 499 posts)
    use the m// operator

    if($test_var =~ m/(d|w)/)
    {$good = 1} else {$good = 0;}
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    27
    Rep Power
    0
    Thanks worked great...

    Used the following to check hex value:
    if($in1 =~ m/[1-9]/)
    {$good = 1;} else {$good = 0;}
    if ($good == 0)
    {
    if($in2 =~ m/[A-F]/)
    {good = 1;} else {$good = 0;}
    }
  6. #4
  7. No Profile Picture
    ledjon
    Guest
    Devshed Newbie (0 - 499 posts)
    N/P

IMN logo majestic logo threadwatch logo seochat tools logo