Re: PHP preg_match question

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Matt Graham
Date:  
To: Main PLUG discussion list
Subject: Re: PHP preg_match question
From: keith smith <>
> I have an input string that should only be lower or upper alphas,
> numbers and can contain a hyphen. I'm trying to figure out how
> to get PHP preg_match to verify the input string only contains these
> chars.


> preg_match("/[a-z0-9\+\-]/", $vaidateStr)


<?php
if(preg_match("/^[a-zA-Z0-9\-]+$/","stuff23AA")){
print "This should print\n";
}
if(preg_match("/^[a-zA-Z0-9\-]+$/","znork_")){
print "This should not print.\n";
}

...The regexp there means "beginning of string, then a sequence of one or more
characters from a-z A-Z 0-9 and -, then the end of the string". So
"stuff23AA" matches, while "znork_" doesn't. Regular expressions can be a
little funky, which is why you always test them against a bunch of stuff
before using them....

--
Matt G / Dances With Crows
The Crow202 Blog: http://crow202.org/wordpress/
There is no Darkness in Eternity/But only Light too dim for us to see

---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss