javascript で検証を行う html サインアップ ページを作成しました。これが検証コードです。
SignUp.html
< script type="text/javascript" >
function validateForm() {
var id = document.signup.LoginId;
var password = document.signup.LoginPassword;
var cpassword = document.signup.ConfirmPassword;
var city = document.signup.City;
var state = document.signup.State;
var number = document.signup.PhoneNumber;
var email = document.signup.Email;
var address = document.signup.Address;
var zipcode = document.signup.ZipCode;
if(id.value == "") {
window.alert("Error: Username should be filled out.");
id.focus();
return false;
}
re = /^\w+$/;
if(!re.test(id.value)) {
window.alert ("Error: Username must contain only letters, numbers and underscores.");
id.focus();
return false;
}
if(id.length < 6) {
window.alert("Error: Username must contain at least 6 charecters.");
id.focus();
return false;
}
if(id.length > 12) {
window.alert("Error: Username must not be greater than 12 charecters.");
id.focus();
return false;
}
if(password.value != "" && password.value == cpasswotd.value) {
if(password.length < 6) {
window.alert("Error: Password must contain at least 6 charecters.");
password.focus();
return false;
}
if(password.length > 12) {
window.alert("Error: Password must not be greater than 12 charecters.");
password.focus();
return false;
}
if(password.value == id.value) {
window.alert("Error: Password must be different from UserName.");
password.focus();
return false;
}
re = /[0-9]/;
if(!re.test(password.value)) {
window.alert("Error: Password must contain at least one number.");
password.focus();
return false;
}
re = /[a-z]/;
if(!re.test(password.value)) {
window.alert("Error: Password must contain at least one lowercase letter (a-z).");
password.focus();
return false;
}
re = /[A-Z]/;
if(!re.test(password.value)) {
window.alert("Error: Password must contain at least one uppercase letters (A-Z).");
password.focus();
return false;
}
}else {
window.alert("Error: Please check that you've entered and Confirmed your Password.");
password.focus();
return false;
}
window.alert("You have entered a valid password: "+password.value);
return true;
if(city.value == "") {
window.alert("City must not be null.");
city.focus();
return false;
}
if(state.value == "") {
window.alert("State must not be null.");
state.focus();
return false;
}
if(number.value == "") {
window.alert("Phone number must not be null.");
number.focus();
return false;
}
if(number.length != 10) {
window.alert("Phone number must be 10 digits.");
number.focus();
return false;
}
if (email.value == "")
{
window.alert("Please enter a valid e-mail address.");
email.focus();
return false;
}
if (email.value.indexOf("@", 0) < 0)
{
window.alert("Please enter a valid e-mail address.");
email.focus();
return false;
}
if (email.value.indexOf(".", 0) < 0)
{
window.alert("Please enter a valid e-mail address.");
email.focus();
return false;
}
re = /^\w+$/
if(!re.test(address.value)) {
window.alert("Error: Address must contain only letters, numbers and underscores.");
address.focus();
return false;
}
if(zipcode.value == "") {
window.alert("Error: Zipcode must not be null.");
zipcode.focus();
return false;
}
if(zipcode.length > 6) {
window.alert("Error: zipcode must not less than 6 digits.");
zipcode.focus();
return false;
}
} < /スクリプト>
「sapan@2」や「sapan」などの間違ったメール アドレスを入力しようとしても、エラー メッセージは表示されず、データベースに保存されます。
誰でもこれを修正するのを手伝ってもらえますか?
ありがとうございました。