Re: regexps
| From: | Daniel James | Date: | Wed, 08 Aug 2001 23:47:24 +0000 |
| Subject: | Re: regexps | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-61923@lists.php.net to get a copy of this message | ||
if (preg_match("/\d/", $data) {
print 'The $data contained a number';
}
On 2001.08.09 07:05 scott [gts] wrote:
> here are two regexps that might do what you want
>
> "\w" matches alphanum (1-9a-zA-z)
>
> IMO, the best way to check for non-alphanum chars is
> to check for "\W" (upper case is negation of alphanum,
> which will match only non-alphanum).
>
>
>
> if (preg_match('/^\w+$/', $data)) {
> print "entirely alphanum
> }
> if (preg_match('/\W+/', $data)) {
> print "Contains non-alphanum!!";
> }
>
>
> > -----Original Message-----
> > From: Kurth Bemis [mailto:kurth@usaexpress.net]
> > Sent: Wednesday, August 08, 2001 4:43 PM
> > To: php-general@lists.php.net
> > Subject: [PHP] regexps
> >
> >
> > i need to find out if a string (user imputed) conatins numbers. I want
>
> > only a-zA-Z to be in a field. (their name for example....and city)...i
>
> > have the following however my regexps are VERY weak as i am a beginner.
> >
> > function validatetext($text){
> > if (is_string($text)== 1){
> > return "good";
> > }else{
> > return "bad";
> > }
> > }
> >
> > ~kurth
> >
> >
> > --
> > 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
> >
>
> --
> 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
>