Yes, that does the trick very nicely! I had been trying for a while and it
was rather late and I just couldn't work it out! If only I had found an
example with the negate (^) ;)

Many thanks. You saved my keyboard from stress related destruction! Hehe

James


-----Original Message-----
From: Doug Brewer [mailto:[EMAIL PROTECTED]]
Sent: 03 March 2001 00:33
To: James Duncan; [EMAIL PROTECTED]
Subject: RE: [PHP-WIN] preg_match

I'm not a regex expert, but can't you use a negated class

if (preg_match ("/[^a-z]/i", $name)) {
        echo "has non alpha chars";
}
else {
        echo "all alphas";
}

sorry, didn't try the above code before sending.

HTH,

Doug

| -----Original Message-----
| From: James Duncan [mailto:[EMAIL PROTECTED]]
| Sent: Friday, March 02, 2001 6:20 PM
| To: [EMAIL PROTECTED]
| Subject: [PHP-WIN] preg_match
|
|
| Help,
|
| This is driving me mad and I know there must be a very
| simple solution. I'm
| trying to detect if my strings contain ONLY certain values.
| For instance, I'
| m trying to limit my "$name" string to just a-z (case insensitive)
| characters. I'm trying to do this with preg_match (unless
| there is an easier
| way). However, I'm failing badly. This is what I have so far:
|
| if (preg_match ("/[a-z]/i", $name))
| {
| echo "string only contains characters ranging between a to z";
| }
| else
| {
| echo "string contains characters outside of the a to z range";
| }
|
| This checks for the occurrence of any a-z characters in the
| string. However,
| want I require is for it to allow JUST those characters. At
| the moment if
| $name = "abc1" then True is returned (I want False returned
| here because of
| the "1"). I don't know how to write this functionality in
| preg_match format
| :-(
|
| Please help
|
| Thanks
|
| James
|


-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to