CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Allowing only letters, numbers and spaces

 



LeoF
Novice

Oct 19, 2000, 9:51 PM

Post #1 of 2 (2874 views)
Allowing only letters, numbers and spaces Can't Post

Hello everyone,

I'm trying to only allow letters, numbers and spaces in a string and I'm using the following expression:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

if ( $this_string =~ /[\W_]/ ) {
print "characters not allowed";
}</pre><HR></BLOCKQUOTE>

Which works for excluding everything that's not a letter or a number, but I don't know how to modify it so it allows for spaces, I've tried several approaches none of which worked, any light on this issue will be greatly appreciated.

Thanks in advance for your cooperation.

Be Well


LeoF
Novice

Oct 20, 2000, 10:07 AM

Post #2 of 2 (2874 views)
Re: Allowing only letters, numbers and spaces [In reply to] Can't Post

Well… it seems this forum has good "vibes" Smile

After posting, it just occurred to me another way to try, and it worked, I used this:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

if ( $this_string =~ /[^a-zA-Z0-9 ]/ ) {
print "characters not allowed";
}</pre><HR></BLOCKQUOTE>

And it allows for spaces but catches everything that is not a letter, a number, or a space.

If you may, I'll appreciate it if someone could tell me if there could be a way to modify the first expression, I would like to know for future reference.

Thanks a lot.

Be Well


[This message has been edited by LeoF (edited 10-20-2000).]

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives