【发布时间】:2015-11-07 22:24:03
【问题描述】:
我有一些关于密码的 javascript 代码的问题。这是我的代码。那部分工作正常,但我想提出另一个条件,即我的密码应包含至少 8 个字符并且必须遵守以下规则:没有空格,至少包含 1 个大写字母和一个数字。关于手机,它必须始终以数字开头。 5.帮助
function formValidation() {
var mobile = document.forms["form"]["mobile"].value;
var password = document.forms["form"]["password"].value;
//reg expression check
var checkNumbers = /^[0-9 ]+$/;
$(document.forms["form"]["mobile"]).focus(function(){
$(document.forms["form"]["mobile"]).css("background-color", "white");
});
$(document.forms["form"]["password"]).focus(function(){
$(document.forms["form"]["password"]).css("background-color", "white");
function clear(){
$(document.forms["form"]["mobile"]).focus(function(){
$(document.forms["form"]["mobile"]).css("background-color", "white");
});
$(document.forms["form"]["password"]).focus(function(){
$(document.forms["form"]["password"]).css("background-color", "white");
});
}
if (mobile == null || mobile == "") {
error[error.length]=("Enter your mobile number");
document.form.mobile.focus();
$(document.forms["form"]["mobile"]).css("background-color", "blue");
;
}else if (mobile != null || mobile != "") {
if(!checkNumbers.test(mobile)){
error[error.length]=("Enter Only numeric Characters for mobile phone");
document.form.mobile.focus();
$(document.forms["form"]["mobile"]).css("background-color", "blue");
}
}
if (password == null || password == "") {
error[error.length]=("Enter a password");
document.form.password.focus();
$(document.forms["form"]["password"]).css("background-color", "blue");
}
}
<form name="form" onsubmit="return formValidation()" action="process.html">
Mobile phone:
<input type="text" name="mobile" id="mobile"></br></br>
Password:
<input type="password" name="password" id="password"></br></br>
</form>
<input id="submit" type="submit" name="submit" id="submit">
【问题讨论】:
标签: javascript forms validation