我有一个包含潜在客户信息字段的表单。垃圾邮件发送者在地址字段中输入网址。当字段包含“http://”时,我希望收到一条错误消息
这是表单代码:
<label>First Name:</label> <input id="first_name" name="first_name" type="text" size="20" />
<label>Last Name:</label> <input id="last_name" name="last_name" type="text" size="20" />
<label>Address:</label> <input name="address" type="text" size="30" />
<label>City, State Zip:</label> <input name="city" type="text" size="20" value="City, State Zip"/>
<label>Phone Number:</label> <input name="phone" type="text" size="20" />
<label>Email:</label> <input id="email" name="email" type="text" size="30" />
这是我的错误代码:
function validateForm(){
message = '';
error = 0;
if (document.contact_form.first_name.value == '') {
message = 'First name is a required field\n';
error = 1;
}
if (document.contact_form.last_name.value == '') {
message = message + 'Last name is a required field\n';
error = 1;
}
if (document.contact_form.phone.value == '') {
message = message + 'Phone Number is a required field\n';
error = 1;
}
if (document.contact_form.email.value == '') {
message = message + 'Email is a required field\n';
error = 1;
}
if (WHAT GOES HERE TO SHOW THAT THE FIELD CAN'T CONTAIN ANY VARIATION OF 'http://?') {
message = message + 'That is not a valid address\n';
error = 1;
}
if (error) {
alert(message);
return false;
} else {
return true;
}
}