私はウェブサイトを作成しており、JavaScriptを使用して情報を検証しています。これはアドレス番号に問題があるコードです。エラーは無効なアドレス番号です
他にエラーがあれば教えてください
ありがとう =)
function validateForm()
{
var form = document.forms['inputForm'];
var formats =
{
first_name: /^[a-zA-Z]+[\-'\s]?[a-zA-Z]+$/, /*works for a-Z allows - and '*/
surname: /^[a-zA-Z]+[\-'\s]?[a-zA-z]+$/, /*works for a-Z allows - and '*/
postcode: /^\d{4}$/, /*4digit post code australia wide*/
email: /^\w+([\.-]w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/, /*allows all word characters and normal email formats*/
address_number: /^\d[0-9]{\?12}$/, /*allows any number of digits*/
address_name: /^\w?\s?[a-zA-Z]+(,?\s([a-zA-Z])*)*$/, /*allows numbers space capital letters and other word characters*/
suburb: /^\w?\s?[a-zA-Z]+(,?\s([a-zA-Z])*)*$/, /*allows numbers space capital letters and other word characters*/
phone: /^\d{10}$/, /*8 number phone number*/
length: /^\d[0-9]$/,
height: /^\d[0-9]$/,
}
var length = form.length.value;
var height = form.height.value;
var area = length*height;
var elCount = form.elements.length;
for(var i = 0; i<elCount; i++)
{
var field = form.elements[i];
if(field.type == 'text')
{
if(!formats[field.name].test(field.value))
{
alert('invalid '+ field.name.replace('_',' ')+'.'); /*alerts the name of the area not filled right in a pop up box*/
field.focus();
return false;
}
}
}
alert('All fields correct, the form will now submit.')
}