【发布时间】:2020-05-18 13:16:14
【问题描述】:
<body>
<p>Enter your email:</p>
<input id="email" style="margin-bottom: 20px; margin-top: 2px;" type="email"
placeholder="Email: ">
<input onclick= "formSubmission(email)" type="submit"
value="Submit">
<script>
const formRecord = []
const formSubmission = (email) =>{
if (email.value){
if (email.value.indexOf('@')){
formRecord.push(`Email :` + email.value)
}
else{
alert(`Please enter the valid email!`)
}
}
else{
return alert(`Please fill the area of email!`)
}
document.write(formRecord)
}
</script>
</body>
我编写了这个逻辑以通过“@”来区分电子邮件,但输出并不顺利。 请告诉我如何在没有正则表达式的情况下封装电子邮件。
【问题讨论】:
-
为什么你绝对要避免正则表达式的超能力?
-
仅检查
@符号的存在不足以验证电子邮件地址。
标签: javascript html function html-email indexof