表单验证电子邮件ID不起作用..任何人都可以帮助我的朋友

时间:2017-01-25 06:51:11

标签: javascript email

我希望只有在使用@格式且单选按钮也不能在javascript中工作时才能验证电子邮件ID,所以我使用html5 .i试图将单选按钮写为复选框格式,但它不能正常工作。一个人帮我朋友

<script>

function validateForm() {
    var x = document.forms["myForm"]["fname"].value;
    if (x == "") {
        alert(" First Name must be filled out");
        return false;
    }
    var y = document.forms["myForm"]["lname"].value;
    if (y == "") {
        alert("Last Name must be filled out");
        return false;
    }
    
     var z = document.forms["myForm"]["email"].value;
    if (z== "") {
        alert("Email must be filled out");
        return false;
    }
    var a = document.forms["myForm"]["fpassword"].value;
	  var b = document.forms["myForm"]["lpassword"].value;
    if(a!=b){  
alert("password must be same!");  
return false;  
}  
 var a = document.forms["myForm"]["fpassword"].value;
    if (a== "") {
        alert("fpassword must be filled out");
        return false;
    }
    var b = document.forms["myForm"]["lpassword"].value;
    if (b== "") {
        alert("lpasswordmust be filled out");
        return false;
    }
   
    var c = document.forms["myForm"]["mobile"].value;
    if (c==""||isNaN(c) || x<10) {
        alert("mobile must be filled out");
        return false;
		
    }
	
	var per=document.getElementById("personal").checked;
    var bus=document.getElementById("bussiness").checked;
	
	if((per=="")&&(bus==""))
	{
	alert("select atleast one option");
	return false;
	}
	return true;
}

	
   





</script>
</body>
</html>
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<title>
Task
</title>

<style>
#i{margin-left:200px;}

h1{text-decoration:underline;
color:#281c0e;}

input[type=password]{width:350px;}

#a{width:350px;}

#b{width:350px;}

input[type=submit]{width:200px;
height:30px;}

#c{margin-left:10px;}



}

</style>

</head>



<body>
<div class="jumbotron">
<h1><b>Create your Google Account</b></h1>
<form name="myForm" action="https://www.google.co.in/"
onsubmit="return validateForm()" method="get">
<div id="i"><b>Name:</b><br>
<input type="text" name="fname" placeholder="First"> <input type="text" id="d" name="lname" placeholder="Last">
<br>
<br>
<b>Choose your Email-id</b>
<br>
<br>

<input id="a" type="text" name="email" placeholder="@gmail.com">

<br>
<br>

<b>Create your Password</b><br>
<input type="password" name="fpassword" placeholder="Password">
<br>
<br>
<b>Confirm your Password</b><br>
<input type="password" name="lpassword" placeholder="Password">
<br>



<br>
<b>Mobile Phone:</b><br>
<input id="b" type="text" name="mobile" placeholder="+91">
<br>
<br>
Account type
<input type="checkbox" id="personal" >Personal
<input type="checkbox" id="bussiness">Bussiness<br><br>
  <input type="radio" value="male" name="rad" required> Male
    <input  type="radio" value="female" name="rad"> Female
<br>

<input type="submit" value="submit"class="btn btn-success" >
</div>
</div>

1 个答案:

答案 0 :(得分:0)

在电子邮件输入文本中设置type="email"。验证将由HTML5处理。

<input id="a" type="text" name="email" placeholder="@gmail.com">