Could do with a little help-please

Discussion in 'PHP' started by links121, May 24, 2012.

  1. #1
    hi

    I have this registation page that i'm having problems with..

    It only understands us zip codes and not anyother like the u.k

    here is the code anyone could help so the php code understands all zip & post codes..
    Thanks in advance..

      
    	Line 14: 		var zipcode				   = "document."+form_name+".txtZIP.value";
    	Line 80: 		 if(eval(zipcode)!='' && validateZIP(eval(zipcode)))
    	Line 80: 		 if(eval(zipcode)!='' && validateZIP(eval(zipcode)))
    	Line 82: 						alert("Enter valid zip code");
    	Line 168: //alert("Please enter your 5 digit or 5 digit+4 zip code.");
    	Line 175: //alert("Invalid characters in your zip code.  Please try again.");
    	Line 179: //alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
     
    	Line 15:    				var zipcode				   = "document."+form_name+".txtZIP.value";
    	Line 71: 	 	var zip_country	   = document.getElementById("billCountrySelect").value;
    	Line 73: 		if(zip_country == "US" || zip_country == "UM")
    	Line 73: 		if(zip_country == "US" || zip_country == "UM")
    	Line 75: 		 if(eval(zipcode)!='' && validateZIP(eval(zipcode)))
    	Line 75: 		 if(eval(zipcode)!='' && validateZIP(eval(zipcode)))
    	Line 77: 						alert("Enter valid zip code");
    	Line 137: //alert("Please enter your 5 digit or 5 digit+4 zip code.");
    	Line 144: //alert("Invalid characters in your zip code.  Please try again.");
    	Line 148: //alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
    PHP:
    Thanks for looking
     
    links121, May 24, 2012 IP
  2. Macaua

    Macaua Greenhorn

    Messages:
    24
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    13
    #2
    Post here the validateZIP javascript function and also the html code of the register page.
     
    Macaua, May 24, 2012 IP
  3. links121

    links121 Well-Known Member

    Messages:
    266
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    121
    #3
    Hi

    Thanks for the reply here are the js code

    return stringValue;
    }

    function validateZIP(field) {
    var valid = "0123456789-";
    var hyphencount = 0;

    if (field.length!=5 && field.length!=10) {
    //alert("Please enter your 5 digit or 5 digit+4 zip code.");
    return true;
    }
    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 true;
    }
    if ((hyphencount > 1) || ((field.length==10) && ""+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 true;
    }

    another one

    }

    var zip_country = document.getElementById("billCountrySelect").value;

    if(zip_country == "US" || zip_country == "UM")
    {
    if(eval(zipcode)!='' && validateZIP(eval(zipcode)))
    {
    alert("Enter valid zip code");
    return false;

    The html from the register.php


    <td align="right">State<span class="required">*</span></td>
    <td align="left">&nbsp;</td>
    <td align="left"> <select id='billStateSelect' class='textarea2' name='bill_state'>
    </select> <SCRIPT type="text/javascript">initCountry(); </SCRIPT> </td>
    </tr>
    <tr><td align="right" >ZIP&nbsp;<span class="required">*</span></td>
    <td >&nbsp;</td><td align="left"><input type="text" value="<?php echo htmlentities($txtZIP);?>" class="textarea" name="txtZIP" maxlength="20"></td></tr>
    <tr>

    Thanks for your help
     
    links121, May 24, 2012 IP
  4. webshore88

    webshore88 Well-Known Member

    Messages:
    131
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #4
    dude, what do you want to do and what problem are you facing? Please describe.
     
    webshore88, May 24, 2012 IP
  5. links121

    links121 Well-Known Member

    Messages:
    266
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    121
    #5
    Hi

    My register.php will only recoginse zip and not post codes

    Thanks
     
    links121, May 24, 2012 IP
  6. links121

    links121 Well-Known Member

    Messages:
    266
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    121
    #6
    Please Anyone ?
     
    links121, May 25, 2012 IP
  7. iMarcus

    iMarcus Active Member

    Messages:
    122
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    90
    #7
    Looks like you need some javascript to accept input of uk postcodes.
    Get someone to rewrite / modify the function validateZIP(field) to allow 4chars + space + 3 chars which is the UK postcode format.
    Also you would need to add 'gb' or 'uk' as a country.
     
    iMarcus, May 25, 2012 IP