var Surname1 = $('#sn1').val();
var Name1 = $('#n2').val();
var Gender1 = $('#g3').val();
var Address1 = $('#a4').val();
var Email1 = $('#em5').val();
var Phone1 = $('#hp6').val();
var emailcheck = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
var phonecheck = /^\d{8}$/;
var gendermcheck = /^[Male]$/;
var genderfcheck = /^[Female]$/;
if (Surname1 == "" || Name1 == "" || Gender1 == "" || Address1 == "" || Email1 == "" || Phone1 == "")
{
alert("Updating failed! Please try again!!!");
return false;
}
else if (!emailcheck.test(Email1))
{
alert("Unable to Update! Please Check your Email Address");
return emailcheck.test(Email1);
}
else if (!phonecheck.test(Phone1))
{
alert("Unable to Update! Please Check your contact number");
return phonecheck.test(Phone1);
}
else if (!genderfcheck.test(Gender1) || gendermcheck.test(Gender1))
{
alert("Type Male/Female");
return genderfcheck.test(Gender1);
return gendermcheck.test(Gender1);
}
else
{
alert("Update was Successful! Thank you for updating our system!");
}
驗證男性和女性如果我想確保用戶只能在保存框中鍵入男性或女性。如果他們輸入男性,它會提示錯誤,我是否有任何方法可以編碼,以便它只能接受「男性」或「女性」?驗證性別
你想要的邏輯是if!test1 &&!test2。也就是說,將人限制在一個性別二元組中是一個糟糕的主意,它採取了一種使某些人的身份無效的政治立場。除非你明白爲什麼這是侮辱性的,並且打算侮辱那些不限制男性/女性性別投入的人。 – acrosman
如果您有一組小的特定有效值,爲什麼不使用下拉菜單或單選按鈕組? –