Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Validation 2

Status
Not open for further replies.

apex82

Programmer
Mar 2, 2009
127
GB
I have validation on a form so the user has to enter something in the fields:

Code:
function CheckForm(Recall) {
	if (Recall.Reference.value == "") {
		alert("Please enter a value for the \"reference number\" field.");
		Recall.Reference.focus();
		return (false);
	}

	if (Recall.Registration.value == "") {
		alert("Please enter a value for the \"Registration \" field.");
		Recall.Registration.focus();
		return (false);
	}

	if (Recall.Make.value == "") {
		alert("Please enter a value for the \" Make \" field.");
		Recall.Make.focus();
		return (false);
	}
	return (true);
}

What I want to do is validate the the Reference field so it only accepts the following format
000-000-000.

How do I do this?

I have been searching for examples but haven’t come across anything similar.

Thanks.
 
Hi

Code:
    if (! Recall.Reference.value[red].match(/^\d{3}(?:-\d{3}){2}$/)[/red]) {
        alert("Please enter a [red]valid[/red] value for the \"reference number\" field.");
        Recall.Reference.focus();
        return (false);
    }

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top