/ Published in: JavaScript
I came across this little snippet... and thought it was rather nice.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<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>