Regular Expression

Would someone mind helping me correct this code?

function regExpression(stringValue) {
	if (stringValue === null || stringValue.length === 0) {
		alert("No string was entered"); }
	else if (stringValue.match(/^[_.-a-z0-9]+@[_.-a-z]+\\.[a-z]{2,4}$/i) != null)
		alert("This is a valid email.");
	else {
		alert("The string is not a valid email."); }
}

The problem is that:

john.smith@gmail123.com

works. The 123 in the provider shouldn’t be allowed, but it is. I’m trying to build a regular expressions for email.

The problem is with this fragment of the regular expression:

[_.-a-z]

The first hyphen (-) is being taken to mean you wish to allow characters between . and a (which includes numbers, and other things you don’t want). To keep this from happening, you need to make the hyphen the first thing in your list of characters:

[-_.a-z]

Thanks a lot Kevin, it worked perfectly. I also look forward to seeing your videos on AJAX!