我正在尝试验证表单中的电话号码。我在提交表格时执行一项功能,该功能具有验证电话号码的程序。如果电话号码不是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',