已知邮箱的用户名只能由数字字母下划线组成,域名为@1000phone.com
//判断一个字符串是否是邮箱,是返回true,不是返回false。
//mail @1000phone.com 是
//$mail @1000phone.com 不是
//mail @1000phone.comp 不是
function checkEmail(str) {
if (str.lastIndexOf("@") == -1) {
return false;
}
var arr = str.split(/@/);
if (arr[arr.length - 1]!="1000phone.com") {
return false;
}
var temp = arr[0];
for (var i = 0; i < arr.length; i++) {
if (!(temp[i] >= 'a' && temp[i] <= 'z'
|| temp[i] >= 'A' && temp[i] <= 'Z'
|| temp[i] >= '0' && temp[i] <= '9'
|| temp[i == '_'])) {
return false;
}
}
return true;
}