Hi, you've probably all been asked this a thousand times already, so I apologise in advance. The question I have is about form validation using Javascript.
I'm making a Registration page for my site. The page has the usual form fields
Username
Email
Password
Confirm Password
What I would like to know is, how to vaildate these fields in detail using javascript.
I have already got so far, but my knowledge of java is pretty bad.
Here's my code
Code:
<script type="text/javascript" language="JavaScript">
function CheckRequiredFields() {
var errormessage = new String();
// field checks
if(WithoutContent(document.form1.username.value))
{ errormessage += "\n\nPlease choose a Username"; }
if(WithoutContent(document.form1.password.value))
{ errormessage += "\n\nPlease choose a Password"; }
if(WithoutContent(document.form1.confirmpass.value))
{ errormessage += "\n\nPlease confirm your Password"; }
if(WithoutContent(document.form1.email.value))
{ errormessage += "\n\nPlease enter a valid Email address"; }
if((document.form1.confirmpass.value) != (document.form1.password.value))
{ errormessage += "\n\nPasswords do not match"; }
// Error Message
if(errormessage.length > 2) {
alert('NOTE:' + errormessage);
return false;
}
return true;
} // end of function CheckRequiredFields()
function WithoutContent(ss) {
if(ss.length > 0) { return false; }
return true;
}
</script>
This works fine, but I don't think it is enough. It needs to also check if the user has entered symbols into the fields. And the email field needs to be checked that it is a vaild email address.
(and if anyone has any other suggestions on what else needs to be checked, that would be great)
Can anyone tell me how to do this in Java?
Thank you!
__________________
Please login or register to view this content. Registration is FREE FREE Online Dating!
Meet your perfect match online right now!
|