simple regex query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi guys

Been tryin to figure out regex and have found some tutorials but some have made things clear and others have confused me.

Anyway for a simple query, if I just wanted to check that a variable has only text and numeric characters would I do something like this
(i want it to fail if it finds a symbol eg: + - { " etc...):

echo  "REG result: " . preg_match('/[a-zA-Z0-9]*/', '{d-fg');

however this resolves to true because there are normal characters (alphabetical characters) so how do I make the expression fail because of the { and - characters in the string?

You can also list which characters you DON'T want -- just use a '^' as the first symbol in a bracket expression
(i.e., "%[^a-zA-Z]%" matches a string with a character that is not a letter between two percent signs). But that would mean that I would have to list each symbol I dont want and that would be undesireable as it would be better to list exactly what the acceptable characters are.

Can anyone give me some insight as to where I'm going wrong?

thanks

--

Angelo

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux