jas
09-25-2002, 10:12 PM
I'm trying to validate phone numbers for my form. I cant figure it out. I've seen where you can do it by matching, but not sure how to do that. Here is my sample form with what I got so far oh yeah I want the format to be (xxx)-xxx-xxxx. If someone can give me some insight that would be great!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>“assignment3</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.2716.2200" name=GENERATOR></HEAD>
<script language="Javascript">
function sampleEntries() {
document.trip.name.value = "Jason"
document.trip.address.value = "3200 Creek Road"
document.trip.city.value = "city"
document.trip.state.value = "AZ"
document.trip.zip.value = "86121"
document.trip.phone.value = "451-1239"
document.trip.rb[1].checked = true
document.trip.vacation.selectedIndex = 2
document.trip.nights.selectedIndex = 3
document.trip.box1.checked = true
document.trip.car.value = "I would like to have an economy class car."
}
function validateInput() {
var LB = "\n";
var msg1 = "Please fill out your:" + LB + LB;
var msg2 = "";
var status = "OK"
var name = document.trip.name.value
var address = document.trip.address.value
var city = document.trip.city.value
var state = document.trip.state.value
var zip = document.trip.zip.value
var phone = document.trip.phone.value
var vacation = document.trip.vacation.selectedIndex
var nights = document.trip.nights.selectedIndex
var car = document.trip.car.value
var box1 = document.trip.box1.checked
var box2 = document.trip.box2.checked
if (name == "") {
msg2 += "Name" + LB;
}
if (address == "") {
msg2 += "Address" + LB;
}
if (city == "") {
msg2 += "City" + LB;
}
if (state == "") {
msg2 += "State" + LB;
}
if (zip == "") {
msg2 += "Zip" + LB;
}
if ((zip != "") && (zip.length !=5 || isNaN(zip))) {
msg2 += "Zip needs to be in nnnnn format" + LB;
}
if (phone == "") {
msg2 += "Phone number" + LB;
}
if (vacation == 0) {
msg2 += "Vacation" + LB;
}
if (nights == 0) {
msg2 += "Nights" + LB;
}
if (box1 == "" && box2 =="") {
msg2 += "Select yes or no" + LB;
}
if (car == "") {
msg2 += "Car" + LB;
}
if (msg2.length > 0){
alert(msg1 + msg2);
return false;
}
else return true;
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>“assignment3</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.2716.2200" name=GENERATOR></HEAD>
<script language="Javascript">
function sampleEntries() {
document.trip.name.value = "Jason"
document.trip.address.value = "3200 Creek Road"
document.trip.city.value = "city"
document.trip.state.value = "AZ"
document.trip.zip.value = "86121"
document.trip.phone.value = "451-1239"
document.trip.rb[1].checked = true
document.trip.vacation.selectedIndex = 2
document.trip.nights.selectedIndex = 3
document.trip.box1.checked = true
document.trip.car.value = "I would like to have an economy class car."
}
function validateInput() {
var LB = "\n";
var msg1 = "Please fill out your:" + LB + LB;
var msg2 = "";
var status = "OK"
var name = document.trip.name.value
var address = document.trip.address.value
var city = document.trip.city.value
var state = document.trip.state.value
var zip = document.trip.zip.value
var phone = document.trip.phone.value
var vacation = document.trip.vacation.selectedIndex
var nights = document.trip.nights.selectedIndex
var car = document.trip.car.value
var box1 = document.trip.box1.checked
var box2 = document.trip.box2.checked
if (name == "") {
msg2 += "Name" + LB;
}
if (address == "") {
msg2 += "Address" + LB;
}
if (city == "") {
msg2 += "City" + LB;
}
if (state == "") {
msg2 += "State" + LB;
}
if (zip == "") {
msg2 += "Zip" + LB;
}
if ((zip != "") && (zip.length !=5 || isNaN(zip))) {
msg2 += "Zip needs to be in nnnnn format" + LB;
}
if (phone == "") {
msg2 += "Phone number" + LB;
}
if (vacation == 0) {
msg2 += "Vacation" + LB;
}
if (nights == 0) {
msg2 += "Nights" + LB;
}
if (box1 == "" && box2 =="") {
msg2 += "Select yes or no" + LB;
}
if (car == "") {
msg2 += "Car" + LB;
}
if (msg2.length > 0){
alert(msg1 + msg2);
return false;
}
else return true;
}
</script>