SunQuest
           Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old July 18th, 2000, 09:53 AM
deviant deviant is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 27 deviant User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
  #2  
Old July 18th, 2000, 02:41 PM
ledjon
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
use the m// operator

if($test_var =~ m/(d|w)/)
{$good = 1} else {$good = 0;}

Reply With Quote
  #3  
Old July 18th, 2000, 04:43 PM
deviant deviant is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 27 deviant User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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;}
}

Reply With Quote
  #4  
Old July 18th, 2000, 06:42 PM
ledjon
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
N/P

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Validating characters - Hex


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway