Return to Snippet

Revision: 10338
at December 19, 2008 17:41 by gembry


Initial Code
<SCRIPT LANGUAGE="JavaScript">
function validate(form) {var e = form.elements, m = '';
	if(!e['firstname'].value) {m += '- First name is required.\n';}
	if(!e['lastname'].value) {m += '- Last name is required.\n';}
	if(!e['address'].value) {m += '- Address is required.\n';}
	if(!e['city'].value) {m += '- City is required.\n';}
	if(!e['postcode'].value) {m += '- Postcode is required.\n';}
	if(!e['telephone'].value) {m += '- Telephone number is required.\n';}
	if(!/.+@[^.]+(\.[^.]+)+/.test(e['email'].value)) {
	m += '- E-mail requires a valid e-mail address.\n';
	}
	if(!e['username'].value) {m += '- Username is required.\n';}
	if(!e['password'].value) {m += '- Password is required.\n';}
	if(e['password'].value != e['confirm'].value) {
	m += '- Your password and confirmation password do not match.\n';
	}
	if(m) {
	alert('The following error(s) occurred:\n\n' + m);
	return false;
	}
	return true;
}
</SCRIPT>

Initial URL

                                

Initial Description
I came across this little snippet... and thought it was rather nice.

Initial Title
Basic Signup Form Validation

Initial Tags
form, validation

Initial Language
JavaScript