admin管理员组文章数量:1326474
in my HTML code i have this
<form name="login">
<p> Email Address <input type="text" name="EmailAddress"> Password <input type="password" name="pword">
<input type="button" value="Submit" onclick="ValidateUser()"></button> </p>
and in my javascript code i have this
function ValidateUser() {
var pword= new RegExp (/^[a-zA-Z0-9]{4,100}$/)
if (pword.test(password)) {
return true
}
else {
alert("Incorrect Password or Username")
}
var email= new RegExp (/^[A-Za-z0-9_.]{2,100}+@[A-Za-z0-9.-]{2,100}+\.[A-Za-z]{2,100}$/)
if (email.test(EmailAddress)) {
return true
}
else {
alert("Incorrect Password or Username")
}
}
When I click the submit button with an incorrect email and password, nothing happens. The email must have at least two characters before the "@" symbol and at least two characters after the ".". The password must have a minimum of four characters, an uppercase character, a lower case character and a n
in my HTML code i have this
<form name="login">
<p> Email Address <input type="text" name="EmailAddress"> Password <input type="password" name="pword">
<input type="button" value="Submit" onclick="ValidateUser()"></button> </p>
and in my javascript code i have this
function ValidateUser() {
var pword= new RegExp (/^[a-zA-Z0-9]{4,100}$/)
if (pword.test(password)) {
return true
}
else {
alert("Incorrect Password or Username")
}
var email= new RegExp (/^[A-Za-z0-9_.]{2,100}+@[A-Za-z0-9.-]{2,100}+\.[A-Za-z]{2,100}$/)
if (email.test(EmailAddress)) {
return true
}
else {
alert("Incorrect Password or Username")
}
}
When I click the submit button with an incorrect email and password, nothing happens. The email must have at least two characters before the "@" symbol and at least two characters after the ".". The password must have a minimum of four characters, an uppercase character, a lower case character and a n
Share Improve this question edited May 1, 2013 at 6:38 Daniele Armanasco 7,45110 gold badges45 silver badges58 bronze badges asked May 1, 2013 at 6:30 Helen BaadeHelen Baade 11 gold badge1 silver badge1 bronze badge 01 Answer
Reset to default 3 var ck_email = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]
{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
function validate(form){
var email = form.email.value;
var password = form.password.value;
var errors = [];
if (!ck_email.test(email)) {
errors[errors.length] = "You must enter a valid email
address.";
}
if (password=='') {
errors[errors.length] = "You must enter the password ";
}
if (errors.length > 0) {
reportErrors(errors);
return false;
}
return true;
}
function reportErrors(errors){
var msg = "Please Enter Valide Data...\n";
for (var i = 0; i<errors.length; i++) {
var numError = i + 1;
msg += "\n" + numError + ". " + errors[i];
}
alert(msg);
}
HTML Code You have to modify action="#"
<form method="post" action="#" onSubmit="return validate(this);" name="login">
</form>
本文标签: htmlHow to validate email and password correctly in JavascriptStack Overflow
版权声明:本文标题:html - How to validate email and password correctly in Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742208911a2433337.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论