Re: [PHP] check for alphanumeric characters

2005-04-29 Thread Matthew Weier O'Phinney
* John Nichel <[EMAIL PROTECTED]>:
> Diana Castillo wrote:
> > what kind of a function can I use that will tell me whether a variable is 
> > alphanumeric (that is has only characters A-Z or 1-9 )?
>
> Something like this should work.  (untested)
>
> preg_match ( "/^([a-z]||[A-Z]||[0-9])+$/", $string )

It can be simpler than that, actually:

preg_match('/^[a-z0-9]+$/i', $string)

(tested and works)

-- 
Matthew Weier O'Phinney   | WEBSITES:
Webmaster and IT Specialist   | http://www.garden.org
National Gardening Association| http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:[EMAIL PROTECTED] | http://vermontbotanical.org

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



Re: [PHP] check for alphanumeric characters

2005-04-29 Thread John Nichel
Philip Hallstrom wrote:
what kind of a function can I use that will tell me whether a variable is
alphanumeric (that is has only characters A-Z or 1-9 )?

http://us3.php.net/manual/en/function.ctype-alnum.php
bool ctype_alnum ( string text )
Checks if all of the characters in the provided string, text, are 
alphanumeric. In the standard C locale letters are just [A-Za-z] and the 
function is equivalent to preg_match('/^[a-z0-9]*$/i', $text).

Returns TRUE if every character in text is either a letter or a digit, 
FALSE otherwise.


Note that if you pass in an empty string you'll also get TRUE...
I always forget about the c_type functions.  Good call.
--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] check for alphanumeric characters

2005-04-29 Thread Philip Hallstrom
what kind of a function can I use that will tell me whether a variable is
alphanumeric (that is has only characters A-Z or 1-9 )?
http://us3.php.net/manual/en/function.ctype-alnum.php
bool ctype_alnum ( string text )
Checks if all of the characters in the provided string, text, are 
alphanumeric. In the standard C locale letters are just [A-Za-z] and the 
function is equivalent to preg_match('/^[a-z0-9]*$/i', $text).

Returns TRUE if every character in text is either a letter or a digit, 
FALSE otherwise.


Note that if you pass in an empty string you'll also get TRUE...
-philip
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] check for alphanumeric characters

2005-04-29 Thread John Nichel
Diana Castillo wrote:
what kind of a function can I use that will tell me whether a variable is 
alphanumeric (that is has only characters A-Z or 1-9 )?


Something like this should work.  (untested)
preg_match ( "/^([a-z]||[A-Z]||[0-9])+$/", $string )
--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] check for alphanumeric characters

2005-04-29 Thread Jay Blanchard
[snip]
what kind of a function can I use that will tell me whether a variable
is 
alphanumeric (that is has only characters A-Z or 1-9 )?
[/snip]

You can use a regular expression, start here http://us3.php.net/regex

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