[英]Why does my email validation script won't get recognized?
Hey so I am really new to HTML and Javascript.嘿,所以我对 HTML 和 Javascript 真的很陌生。 I got a task today to code an Email validation script.我今天的任务是编写 Email 验证脚本。 I think that my script should be fine but for some reason the website doesn't do anything when I click on my submit button.我认为我的脚本应该没问题,但是由于某种原因,当我单击提交按钮时,网站没有做任何事情。 Here is my script:这是我的脚本:
HTML Form: HTML 表格:
<form class="contact-form" action="contact.html" method="post">
<input type="text" class="contact-form-text" placeholder="Your name*" value="" id="name">
<input type="email" class="contact-form-text" placeholder="Your email*" id="email">
<input type="text" class="contact-form-text" placeholder="Your phone*" id="nummer">
<textarea class="contact-form-text" placeholder="Your message"></textarea>
<p id="pflicht">* sind Pflichtfelder</p>
<input type="button" class="contact-form-btn" value="Send" onclick="multiFunction()">
</form>
And this is my function:这是我的 function:
function checkforEM(value){
var laenge = value.length;//6
if(value.indexOf("@") > 0){
alert("@ ist da und nicht ganz vorne");
}
else{
alert("@ ist nicht da oder auf Pos 1");
}
// das @ darf nicht am Ende sein
// Frage: wie finde ich das raus?
// Ich prüfe, ob der Indexwert von @ == 5 ist
if(value.indexOf("@") == laenge - 1){ //5
alert("@ ist am Ende");
}
if(value.substring(value.length-3) == ".de"){
alert("Ist eine .de-Top-Level-Domain");
}else{
alert("Ist keine .de-Top-Level-Domain");
}
}
I am using a function that combines mutiple functions at a time and it looks like this:我正在使用一次组合多个功能的 function,它看起来像这样:
function multiFunction(){
checkforBlank();
checkforNu();
checkforNa();
checkforEM(this.value);
}
Thanks in advance!提前致谢!
If you use input type="email"
, then the email validation is done inside the browser and you do not need to write your own code for it.如果您使用input type="email"
,则 email 验证在浏览器内完成,您无需为此编写自己的代码。 And to require a form field to be entered use the required
attribute.并要求输入表单字段,请使用required
属性。
<input type="email" class="contact-form-text" placeholder="Your email*" id="email" required>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.