You answered my last question very well. However When I added on more forms on to this particular webpage it started to do the same thing again.Which is to show out of order thing in the alert message.
Here's the code below. Thank for your time and consideration:
<html>
<head>
<title>ssn Checker</title>
<script type="text/javascript">
msgAr = new Array();
msgAr[0] = "\nINVALID SSN";
msgAr[1] = "\nINVALID Address (Ex. 1234 Main St.)";
msgAr[2] = "\nINVALID ZIP CODE (Ex. 30064 five digits)";
msgAr[3] = "\nINVALID STATE CODE, Enter Srate Code in Uppercases (Ex. NY, for New York)";
msgAr[4] = "\nINVALID PHONE NUMBER (Ex. 412-828-3000)";
msgAr[5] = "\nINVALID Email Address (Ex. [email protected])";
var bool = false;
var msg = "";
var RE_SSN = /^[0-9]{3}[\- ]?[0-9]{2}[\- ]?[0-9]{4}$/;
var isAddressOk = /^\d{1,6}\s\w{3,16}\s\w{2,8}\w*$/;
var zIP = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
var isStateOk = /^A[LKSLZRAEP]|C[AOT]|D[EC]|F[LM]|G[AU]HI|I[ADLN]|K[SY]|LA|M[ADEHINOPST]IN[CDEHJMVY|O[HKR]|P[ARW]|RI|S[CD]|T[NX]|UT|V[ALT]|W[AIVY]$/;
var isPhoneOk = /^([0-9](|-)?)?(\(?[0-9]{3}\)?|[0-9]{3})(|-)?([0-9]{3}(|-)?[0-9]{4}|[a-zA-Z0-9]{7})$/;
var isEmailOk = /^[A-Za-z0-9] (([_\.\-]?[a-zA-Z0-9]+)*)@([A-Z a-z]+)(([\.\-]?[a-zA-z0-9]+)*)\.([A-Za-z]{2,})$/ ;
//alertMsg += alert("");
function checkSsn(ssn){
if (RE_SSN.test(ssn)){
("VALID SSN");
} else {
//alert("INVALID SSN");
bool = true;
msg += msgAr[0];
}
showMsg();
}
function checkAD(address){
if (isAddressOk.test(address)){
("VALID input");
} else {
//alert("INVALID Address (Ex. 1234 Main St.)");
bool = true;
msg += msgAr[1];
}
}
function checkZ(zip){
if(isEmailOk.test(zip)){
("VALID input");
} else{
bool = true;
msg += msgAr[2];
}
}
function checkST(state){
if(isStateOk.test(state)){
("VALID input");
} else{
bool = true;
msg += msgAr[3];
}
}
function checkPH(phone){
if(isPhoneOk.test(phone)){
("VALID input");
} else{
bool = true;
msg += msgAr[4];
}
}
function checkEM(email){
if(isEmailOk.test(email)){
("VALID input");
} else{
bool = true;
msg += msgAr[5];
}
}
function showMsg(){
if (bool){
bool = false; //reset flag
alert(msg);
msg = '';
} else {
return false;
}
}
</script>
</head>
<body>
<form onsubmit="return false;" >
<input type="text" id="ssn" size="20">
<input type="text" id="address" size="20"/>
<input type="text" id="zip" size="30" />
<input type="text" id="uemail" size="30" />
<input type="text" id="pnumber" size="30" />
<input type="submit" value="Submit Form"
onclick = " checkAD(this.form.address.value); checkSsn(this.form.ssn.value); checkEM(this.form.uemail.value); checkPH(this.form.pnumber.value); checkST(this.form.state.value); checkZ(this.form.zip.value); " />
</form>
</body>
</html>
Here's the code below. Thank for your time and consideration:
<html>
<head>
<title>ssn Checker</title>
<script type="text/javascript">
msgAr = new Array();
msgAr[0] = "\nINVALID SSN";
msgAr[1] = "\nINVALID Address (Ex. 1234 Main St.)";
msgAr[2] = "\nINVALID ZIP CODE (Ex. 30064 five digits)";
msgAr[3] = "\nINVALID STATE CODE, Enter Srate Code in Uppercases (Ex. NY, for New York)";
msgAr[4] = "\nINVALID PHONE NUMBER (Ex. 412-828-3000)";
msgAr[5] = "\nINVALID Email Address (Ex. [email protected])";
var bool = false;
var msg = "";
var RE_SSN = /^[0-9]{3}[\- ]?[0-9]{2}[\- ]?[0-9]{4}$/;
var isAddressOk = /^\d{1,6}\s\w{3,16}\s\w{2,8}\w*$/;
var zIP = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
var isStateOk = /^A[LKSLZRAEP]|C[AOT]|D[EC]|F[LM]|G[AU]HI|I[ADLN]|K[SY]|LA|M[ADEHINOPST]IN[CDEHJMVY|O[HKR]|P[ARW]|RI|S[CD]|T[NX]|UT|V[ALT]|W[AIVY]$/;
var isPhoneOk = /^([0-9](|-)?)?(\(?[0-9]{3}\)?|[0-9]{3})(|-)?([0-9]{3}(|-)?[0-9]{4}|[a-zA-Z0-9]{7})$/;
var isEmailOk = /^[A-Za-z0-9] (([_\.\-]?[a-zA-Z0-9]+)*)@([A-Z a-z]+)(([\.\-]?[a-zA-z0-9]+)*)\.([A-Za-z]{2,})$/ ;
//alertMsg += alert("");
function checkSsn(ssn){
if (RE_SSN.test(ssn)){
("VALID SSN");
} else {
//alert("INVALID SSN");
bool = true;
msg += msgAr[0];
}
showMsg();
}
function checkAD(address){
if (isAddressOk.test(address)){
("VALID input");
} else {
//alert("INVALID Address (Ex. 1234 Main St.)");
bool = true;
msg += msgAr[1];
}
}
function checkZ(zip){
if(isEmailOk.test(zip)){
("VALID input");
} else{
bool = true;
msg += msgAr[2];
}
}
function checkST(state){
if(isStateOk.test(state)){
("VALID input");
} else{
bool = true;
msg += msgAr[3];
}
}
function checkPH(phone){
if(isPhoneOk.test(phone)){
("VALID input");
} else{
bool = true;
msg += msgAr[4];
}
}
function checkEM(email){
if(isEmailOk.test(email)){
("VALID input");
} else{
bool = true;
msg += msgAr[5];
}
}
function showMsg(){
if (bool){
bool = false; //reset flag
alert(msg);
msg = '';
} else {
return false;
}
}
</script>
</head>
<body>
<form onsubmit="return false;" >
<input type="text" id="ssn" size="20">
<input type="text" id="address" size="20"/>
<input type="text" id="zip" size="30" />
<input type="text" id="uemail" size="30" />
<input type="text" id="pnumber" size="30" />
<input type="submit" value="Submit Form"
onclick = " checkAD(this.form.address.value); checkSsn(this.form.ssn.value); checkEM(this.form.uemail.value); checkPH(this.form.pnumber.value); checkST(this.form.state.value); checkZ(this.form.zip.value); " />
</form>
</body>
</html>