RE: [PHP] RegExp Problem

From: Date: Wed, 18 Oct 2000 08:31:48 +0000
Subject: RE: [PHP] RegExp Problem
Groups: php.general 
Request: Send a blank email to php-general+get-20843@lists.php.net to get a copy of this message
good example ... -----Original Message----- From: Lars Torben Wilson [mailto:torben@pinc.com] Sent: Wednesday, October 18, 2000 5:25 PM To: mukulsabharwal@yahoo.com Cc: php-general@lists.php.net Subject: Re: [PHP] RegExp Problem Mukul Sabharwal writes: > Hi, > > I want to do the following : > > a variable with the following values to be accepted > ... > > if $variable contains > > (1) numbers > (2) underscores > (3) letters > > to be approved and anything else to be disapproved.. > how do i do this.... > > I would like to use pcre for this (preferably) but > ereg would also do.... > > thanks... With preg_match(): if (preg_match('/^\w+$/', $str)) { echo "Matched\n"; } else { echo "Didn't match\n"; } With ereg(): if (ereg('^[[:alnum:]_]+$', $str)) { echo "Matched\n"; } else { echo "Didn't match\n"; } Both of these require the string to not be empty: if the string may be empty, replace the '+' with a '*'. Good luck, Torben -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#20843) next »