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

Re: Allow only letters and numbers?

Thread Previous | Thread Next
February 21, 2002 19:50
Re: Allow only letters and numbers?
Message ID:
>>>>> "Timothy" == Timothy Johnson <> writes:

Timothy> If you don't mind having underscores in your text, you could also do this:

Timothy> if($string !~ /^\w+$/){  #If the string does not have only letters, digits,
Timothy> and underscores from start to finish (\w)

Nope, that also permits "fred\n".  Remember that $ is the same as /\n?\z/.
You want \z instead.

Very common mistake, and could have drastic effects on security.

Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<> <URL:>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See for onsite and open-enrollment Perl training!

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About