我正在尝试以表格形式验证电话号码。我在提交表单时执行一个函数,该函数具有验证电话号码的过程。如果电话号码不是 10 位数,我会停止该功能,提醒用户他们需要输入有效的 10 位数电话号码。
var valPhone = validatePhoneNumber;
var valPhoneThis = valPhone(txtPhoneNumber);
if(!valPhoneThis)
{
alert("Please enter your 10-digit phone number, numbers only.");
return false;
}
else
{
//
}
不确定这里出了什么问题,但它会显示多个带有相同消息的警报框。如果有帮助,我正在创建一个 jQuery 移动应用程序。
$('#create-new-account-button').click(function()
{
$('#create-account-dialog').css('display','block');
txtFirstName = $('#ca-first-name').val();
txtLastName = $('#ca-last-name').val();
txtDateOfBirth = $('#ca-date-of-birth').val();
txtZipCode = $('#ca-zip-code').val();
txtPhoneNumber = $('#ca-phone-number').val();
radGenderMale = $('#ca-radio-gender-male').val();
radGenderFemale = $('#ca-radio-gender-female').val();
txtLogin = $('#ca-email-username').val();
txtPassword = $('#ca-password').val();
// VALIDATION
// Validate Gender
var valGender='';
if(document.getElementById('ca-radio-gender-male').checked)
{
// Male radio button is checked
valGender = "M";
}
else if(document.getElementById('ca-radio-gender-female').checked) {
// Female is checked
valGender = "F";
}
else
{
alert("Please select a gender");
}
// Validate phone number
var valPhone = validatePhoneNumber;
var valPhoneThis = valPhone(txtPhoneNumber);
if(!valPhoneThis)
{
alert("Please enter your 10-digit phone number, numbers only.");
return false;
}
else
{
//
}
// Validate for Blank Fields
// Iterate through all fields to verify there is data in all of them
var blankArray = [];
$(".create-account-field").each(function (i) {
var thisVal = $(this).val();
var thisProp = $(this).prop('placeholder');
if ( thisVal == "" )
{
blankArray.push(thisProp);
}
else
{
// console.log(thisVal);
}
});
var blankArrayString = blankArray.join(", ");
if(blankArrayString == "")
{
$.ajax({
type: 'POST',