JSFiddle - React, Tailwind, and code Playground

by artwl

HTML

userName:
<input type="text" id="username" />
<input type="button" value="GO" id="sub" />

JavaScript

var emailDomains = [
    "@gmail.com",
    "@163.com",
    "@yahoo.com",
    "@qq.com",
    "@126.com",
    "@outlook.com",
    "@hotmail.com",
    "@msn.com"];

window.onload = init;

function init() {
    var un = document.getElementById("username"),
        btn = document.getElementById("sub");
    btn.onclick = function (e) {
        var val = un.value;
        if (val.indexOf("@") != -1) {
            val = "@" + val.split("@")[1];
            if (emailDomains.join(",").indexOf(val) == -1) {
                alert("不包含邮箱域名");
            } else {
                alert("已包含邮箱域名");
            }
        }
    }
}