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?

    Regular expressions can be tricky! You need to get your hands on a 
    good tutorial, then re-read the docs and then practice! :)

    Check - also, this type of question pops up on the PHP
    general mailing often - check that lists archives.

    To briefly answer your question:
    Your regular expression roughly translates to:    

    Match a single alpha or numeric character ([a-zA-Z0-9]), 
    followed by one or more numeric characters ([0-9]+),
    followed by a single numeric character ([a-zA-Z]),
    followed by a single alpha or numeric character ([0-9a-zA-Z])
    at any point within $fieldvalue.

    What you likely want is something like:
        eregi ("^[a-z0-9]+$", trim ($fieldvalue))

    which translates to:
    From the start of the string (^),
    match one or more alpha or numeric characters ([a-z0-9]+)
    (and nothing else) to the end of the string ($)

    eregi() does case-insensitive matching, so you only need 
    to specify lower case letters. eregi handles matching
    upper case automatically.

    Use trim() to remove any trailing or leading whitespace
    from the value.

    Good Luck!


PHP Database Mailing List (
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to