develooper Front page | perl.beginners | Postings from February 2002

Allow only letters and numbers?

Thread Next
From:
Daniel Falkenberg
Date:
February 21, 2002 16:49
Subject:
Allow only letters and numbers?
Message ID:
3ACA70B144BD6D45B994CAC2CA4B9F98017CE0@opal.vintek.local
Hello List,

The code below of coarse will count all characters in the string $string

$string = "4556jhkl";

$count = $string =~ tr/a-zA-Z0-9//;

How would I go about only allowing numbers and letters of the alpahbet?

if ( $string =~ /\dw/)) {
  print "Only letters and numbers allowed: NO SPECIAL CHARACTERS!";
else {
  print "You did it?";
}

Does this look correct to any one?

Regards,

Dan


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About