本文发表在 rolia.net 枫下论坛/\w{2,}@(\w|\-|\_){3,}\.((\w|\-|\_){2,}\.){0,2}[a-z]{2,3}$/i
This is saying that for example an email address:
FIRST@SECOND.com
The regular express is saying that we allow minimum of 2 letters or numbers in the FIRST. Then follow by @. Then the second portion contains at least 3 letters or numbers, or "-", or "_". And the second portion can be repeated maximum of twice with the dot (eg. Hua@server.microsoft.com is accepted, but hua@server1.server2.microsoft.com is not). The follow by a dot. Then the COM portion can be ONLY letters (no numeric or other characters) and it can only be 2 to 3 letters.
eg. The following input won't be accepted.
thisthatthisthat@hotmail (no .?? component)
t@hotmail.com (only 1 letter before@)
this@hotmail.comm (4 letters at the end, max can be only 3)
this@hotmail.c (1 letter at the end, min is 1)
this.that@hotmail.com (the first part cannot have dot)
this.that@ser.server1.hotmail.com (too complex at the end)
thisthat (no @)
All langugages have regular expression and you should use this to validate inputs.
In javascript:
var temp = trim(tt.email.value)
var pattern = /\w{2,}@(\w|\-|\_){3,}\.((\w|\-|\_){2,}\.){0,2}[a-z]{2,3}$/i
if (pattern.exec(temp) == null) {
alert("You have to enter a valid email address")
tt.email.focus();
return false;
}更多精彩文章及讨论,请光临枫下论坛 rolia.net