【发布时间】:2020-02-12 17:29:21
【问题描述】:
我正在做表单验证,要求是 1.Email:Email必须是有效的Email ID。 2.密码:必须是八个字符长。只允许使用数字 (0-9) 和字母 (A-Z,a-z)。 3.FirstName:不能包含任何数字(0-9)。 4.LastName :不能包含任何数字(0-9)。 我为电子邮件地址做了,我对密码和名字验证感到震惊.. 任何人都可以帮助我提前致谢。
<form>
<label for="">First Name</label>
<input type="text" id="fname"><br>
<label for="">Last Name</label>
<input type="text" id="lname"><br>
<label for="">Email</label>
<input type="text" id="email"><br>
<label for="">Password</label>
<input type="text" id="password"><br>
<button type="button" onclick="claim()">Claim Your Free Trail</button>
<p>You Are Agreeing to Our <a href="#">Terms & Condition</a></p>
</form>
<script>
function claim(){
var obj ={
fname:"",
lname:"",
email:"",
password:""
}
for(a in obj){
obj[a]=document.getElementById(a).value
}
if(obj.email.match(/@/) != null){
}else{
alert("Please enter Valid Email Address")
}
console.log(obj)
}
</script>
</body>
【问题讨论】:
标签: javascript formvalidation.io