Hello Ron,
Thursday, January 13, 2005, 8:17:51 AM, you wrote:
R> I am trying to do a simple check to make sure a string contains at
R> least an alphanumeric character before I print the string. How can
R> I do this?
if (preg_match("/[a-zA-Z0-9]+/"),$str) {
echo $str;
}
There may be a more efficient means, but this will work.
Basically if there are any lowercase, and/or uppercase, and/or
numbers, it'll echo $str.
The '+' means one or more times.
You could write it like this too:
if (preg_match("/[a-z0-9]+/i"),$str)
Which is a bit shorter. The 'i' means case insensitive so you can get
rid of the A-Z part (or vice-versa a-z).
Another possibility is:
if (preg_match("/[\w]+/"),$str)
which is shorter still.
'\w' means letters and numbers, but also the underscore character, so
it may not be what you want.
Hope it helps.
--
Leif (TB lists moderator and fellow end user).
Using The Bat! 3.0.2.3 Rush under Windows XP 5.1
Build 2600 Service Pack 2 on a Pentium 4 2GHz with 512MB
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php