我正在创建一个网站,我正在使用 javascript 来验证信息这是我遇到 address_number 问题的代码错误是无效的地址号
如果还有其他错误请说
谢谢 =)
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.')
}