Ah yes, I also forgot the uppercase chars
if ($vaidateStr == preg_replace("/[^a-zA-Z0-9\-]/", "", $vaidateStr)) {
/true, or valid...
}
BTW also as Eric says, the carrot (^) inside the square brackets means
"anything but" (negation), thus how this works..
Ben
On Wed, Jul 20, 2011 at 9:38 PM, Eric Cope <
eric.cope@gmail.com> wrote:
> Here is the regular expression:
>
> /^[a-zA-Z0-9\-]+$/
>
> the ^ requires the pattern match at the beginning of the string.
> The + requires at least one of these characters, but no upper limit. You
> can use * if you don't need the lower limit of 1.
> $ requires the patten match all the way to the end of the string.
> The dash requires escaping, hence the back slash.
>
> http://www.regular-expressions.info/anchors.html
>
> Thanks,
> Eric
>
> On Wed, Jul 20, 2011 at 8:34 PM, keith smith <klsmith2020@yahoo.com>wrote:
>
>>
>> Hi,
>>
>> 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.
>>
>> I tried some thing like this and it always returns true if I have one or
>> more of the specified chars, even if I have a char that is not specified.
>>
>> I need a true for any string that contains Alphas and/or numbers and/or
>> one or more hyphens. I need it to return if the string contains anything
>> else.
>>
>> preg_match("/[a-z0-9\+\-]/", $vaidateStr)
>>
>> I do not need to use preg_match, I'm looking for a simple solution.
>>
>> Any pointers are much appreciated.
>>
>> ------------------------
>> Keith Smith
>> ---------------------------------------------------
>> PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
>> To subscribe, unsubscribe, or to change your mail settings:
>> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
>>
>
>
> ---------------------------------------------------
> PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
> To subscribe, unsubscribe, or to change your mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
>
--
---
Ben
*print ''.join(map(lambda x: chr(x), ( (ord('a')-(3*5)),
int(math.sqrt(math.pi*76)*5+2), int(math.ceil(math.e)*28),
int(math.floor(math.e)*35), long(abs(4%3*35+3)*2))))*
---------------------------------------------------
PLUG-discuss mailing list -
PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss