I'm studying a teach yourself php book and have trouble understanding the following regular expression which should check for a valid form input of an email address:
^[0-9a-zA-Z_\.-]{1,}@([0-9a-zA-Z_\-]{1,}\.)+[0-9a-zA-Z_\-]{2,}$
First of all, the book says that the username and (sub)domain part should also include an "_", "-"and "+" character. I think the "+" character should read a "." character?
If so... in:
[0-9a-zA-Z_\.-]
an escape () character is used before the "." character. I guess this is done to take the "." character literally. But I've also learned so far that the escape character doesn't have to be used if special php symbols, such as the "." character, are used between brackets. So shouldn't it be this?:
[0-9a-zA-Z_.-]
And for the top level domain part:
[0-9a-zA-Z_\-]{2,}
Shouldn't it be just this?:
[a-zA-Z]{2,}
because in top level domains no numbers and characters lide "_" "\" and "-" are used? (again, an escape character is being used between brackets where it's not necessary?)
Am I right in thinking (as a newbie to php and regexp) that the complete regexp should be something like this?:
^[0-9a-zA-Z_.-]{1,}@([0-9a-zA-Z_-]{1,}\.)+[a-zA-Z]{2,6}$