ok here goes nothing.. this may seem a bit confusing but first lt me post my head... the first javascript is to verify the email address entered is in the correct format etc.. the second part is to make sure they enter the same password twice and it is atleast 6 letter lon and doesnt contain space etc. My form name is emailform if you want to make sure i got the script right too... i got it off javascript.com and have tested both scripts seperatly.. i just dont know how to combine them both
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function emailCheck (emailStr) {
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];
for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("(In the email section) The username contains invalid characters.");
return false;
}
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("(In the email section) The domain name contains invalid characters.");
return false;
}
}
if (user.match(userPat)==null) {
alert("(In the email section) The username doesn't seem to be valid.");
return false;
}
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray>255) {
alert("(In the email section) Destination IP address is invalid!");
return false;
}
}
return true;
}
// Domain is symbolic name. Check if it's valid.
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr.search(atomPat)==-1) {
alert("(In the email section) The domain name does not seem to be valid.");
return false;
}
}
if (checkTLD && domArr[domArr.length-1].length!=2 &&
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("(In the email section) The address must end in a well-known domain or two letter " + "country.");
return false;
}
if (len<2) {
alert("(In the email section) This address is missing a hostname!");
return false;
}
// If we've gotten this far, everything's valid!
return true;
}
// End -->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function validatePwd() {
var invalid = " "; // Invalid character is a space
var minLength = 5; // Minimum length
var pw1 = document.emailform.password.value;
var pw2 = document.emailform.password2.value;
// check for a value in both fields.
if (pw1 == '' || pw2 == '') {
alert('Please enter your password twice.');
return false;
}
// check for minimum length
if (document.emailform.password.value.length < minLength) {
alert('Your password must be at least ' + minLength + ' characters long. Try again.');
return false;
}
// check for spaces
if (document.emailform.password.value.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed.");
return false;
}
else {
if (pw1 != pw2) {
alert ("You did not enter the same new password twice. Please re-enter your password.");
return false;
}
else {
alert('Nice job.');
return true;
}
}
}
// End -->
</script>
</head>
This next part is the beginning of my form... when submitted i want it to perform both of the checks... <FORM action="http://www.response-o-matic.com/cgi-bin/rom.pl" method="POST" name=emailform onSubmit="return emailCheck(this.email.value)" onSubmit="return validatePwd()">
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function emailCheck (emailStr) {
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];
for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("(In the email section) The username contains invalid characters.");
return false;
}
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("(In the email section) The domain name contains invalid characters.");
return false;
}
}
if (user.match(userPat)==null) {
alert("(In the email section) The username doesn't seem to be valid.");
return false;
}
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray>255) {
alert("(In the email section) Destination IP address is invalid!");
return false;
}
}
return true;
}
// Domain is symbolic name. Check if it's valid.
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr.search(atomPat)==-1) {
alert("(In the email section) The domain name does not seem to be valid.");
return false;
}
}
if (checkTLD && domArr[domArr.length-1].length!=2 &&
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("(In the email section) The address must end in a well-known domain or two letter " + "country.");
return false;
}
if (len<2) {
alert("(In the email section) This address is missing a hostname!");
return false;
}
// If we've gotten this far, everything's valid!
return true;
}
// End -->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function validatePwd() {
var invalid = " "; // Invalid character is a space
var minLength = 5; // Minimum length
var pw1 = document.emailform.password.value;
var pw2 = document.emailform.password2.value;
// check for a value in both fields.
if (pw1 == '' || pw2 == '') {
alert('Please enter your password twice.');
return false;
}
// check for minimum length
if (document.emailform.password.value.length < minLength) {
alert('Your password must be at least ' + minLength + ' characters long. Try again.');
return false;
}
// check for spaces
if (document.emailform.password.value.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed.");
return false;
}
else {
if (pw1 != pw2) {
alert ("You did not enter the same new password twice. Please re-enter your password.");
return false;
}
else {
alert('Nice job.');
return true;
}
}
}
// End -->
</script>
</head>
This next part is the beginning of my form... when submitted i want it to perform both of the checks... <FORM action="http://www.response-o-matic.com/cgi-bin/rom.pl" method="POST" name=emailform onSubmit="return emailCheck(this.email.value)" onSubmit="return validatePwd()">