|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi all,
Rookie here wondering if anyone could help me on my last day of work. (Fri) I have to turn this code over to someone else and it does work exactly right. Here is the problem: Validate Zip works great, checks for proper length as well as allowing only numbers to be entered in. SSN_check has the same check that won't allow you to enter characters, but it doesn't work. Exactly the same code here, but one works and one won't. Did I call it wrong? Thanks for any suggestions. function SSN_check(field, len){ var valid2 = "0123456789"; var hyphencount2= 0; if (field.length !=len) { alert ("Your Social Security Number entry should be 9 digits."); return; } for (var i=0; i < field.length; i++) { temp = "" + field.substring(i, i+1); if (valid2.indexOf(temp) == "-1") { alert("Invalid characters in the Soc. Sec. Number. Please try again."); return false; } return true; }} // end --> <!-- This function works perfectly. function validateZIP(field) { var valid = "0123456789-"; var hyphencount = 0; if (field.length!=5 && field.length!=9 && field.length!=10) { alert("Please enter your 5 digit or 5 digit+4 zip code."); return false; } for (var i=0; i < field.length; i++) { temp = "" + field.substring(i, i+1); if (temp == "-") hyphencount++; if (valid.indexOf(temp) == "-1") { alert("Invalid characters in your zip code. Please try again."); return false; } if ((field.length ==9) | | (field.length == 10)){ if ((hyphencount != 1) && (field.charAt(5)!="-")) { alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'. Please try again."); return false; }} } return true; } // end --> BODY... Soc. Sec. Number: <input type= "text" name ="SSNum1" onKeyUp="return autoTab(this, 3, event);" size="4" maxlength="3" value="" onchange = "SSN_check(SSNum1.value,3)">-<input type= "text" name ="SSNum2" onKeyUp="return autoTab(this, 2, event);" size="3" maxlength="2" value="" onchange = "SSN_check(SSNum2.value,2)">-<input type= "text" name ="SSNum3" onKeyUp="return autoTab(this, 4, event);" size="5" maxlength="4" value = "" onchange = "SSN_check(SSNum3.value,4)" onFocus="nextfield ='Last_name';"> Zip:<input type= "text" name ="Zip" size=10 maxlength=10 value = "" onchange="validateZIP(Zip.value)" onFocus="nextfield ='Phone_a';"> |
![]() |
| Viewing: Dev Shed Forums > Web Design > HTML Programming > Validate Zip vs Validate Soc Sec |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|