Re: problem with regular expression

From: Date: Mon, 16 Jul 2001 07:43:36 +0000
Subject: Re: problem with regular expression
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-10437@lists.php.net to get a copy of this message
In article <001601c10dc9$e4513780$8d00a8c0@imanila.com.ph>, eper@tridel.net (Jennifer Arcino Demeterio) wrote: > i have a script to identify if the input is a combination of letters and > numbers > > if (eregi("[a-zA-Z0-9][0-9]+[a-zA-Z][0-9a-zA-Z]",$fieldvalue)) > print "alphanumeric" > } else { > not an alphanumeric > } > > my problem is, when the string ends with a number, for example hello123, it > says "not an alpanumeric" ... it works fine when the number is placed before > the letters or in between letters ... why is that? Your regex matches a pattern of: -one alphanumeric -followed by one or more digits -followed by one letter -followed by one alphanumeric The string "hello123" is failing because it does not match the specified pattern. (If "123hello" or "he123llo" really is passing as you describe, re-check your code because that should not be possible given the above regex.) If you want to know if the entire string consists (from beginning to end) of any combination of alphanumeric characters, try: "^[[:alnum:]]+$" -- CC

« previous php.db (#10437) next »