42 users online (0 members and 42 guests)  


  Results 1 to 2 of 2

Related

  1. Javascript Function    Forum: Javascript Forum
    Replies: 0
  2. HTML Function    Forum: Javascript Forum
    Replies: 2
  3. die function    Forum: CGI Perl Forum
    Replies: 2
  1. #1
    anurag.kantak's Avatar
    New User

    Status
    Offline
    Join Date
    May 2007
    Posts
    1

    Need help How one can use substr (); function with numeric value.

    Hi all,
    I am new developer and in trouble I would like to validate a zip code so that I want to split up the user input in three parts using Substr (), please go through below code, please some one help me.

    Code:
    function bzipvalid(textbox){
    	var rawval = textbox.value.toString;
    	var firsttwo = rawval.substr(0, 1);
    	var sectwo = rawval.substr(2, 3);
    	var lasttwo = rawval.substr(4, 5);
    	if (firsttwo != 56){
    		alert("Error no:1205 We are Extremely Sorry,\nThis is not Zip code\nPlease Reinsert Zip Code\nThank you.");
    		textbox.focus();
    		return false;
    	} else if((sectwo != 00) || (sectwo != 12) || (sectwo != 21)){
    		alert("Error no:1206 We are Extremely Sorry,\nThis is not Zip code\nPlease Reinsert Zip Code\nThank you.");
    		textbox.focus();
    		return false;
    	} else if ((sectwo = = 00) && (lasttwo > 97)){
    		alert("Error no:1207 We are Extremely Sorry,\nThis is not Zip code\nPlease Reinsert Zip Code\nThank you.");
    		textbox.focus();
    	} else if ((sectwo = = 12) && ((lasttwo != 01) || (lasttwo != 16) || (lasttwo != 27))){
    		alert("Error no:1207 We are Extremely Sorry,\nThis is not Zip code\nPlease Reinsert Zip Code\nThank you.");
    		textbox.focus();
    	} else if ((sectwo = = 21) && ((lasttwo != 08) || (lasttwo != 10) || (lasttwo != 20) || (lasttwo != 22) || (lasttwo != 30) || (lasttwo != 34) || (lasttwo != 35) || (lasttwo != 44) || (lasttwo != 45) || (lasttwo != 49) || (lasttwo != 51) || (lasttwo != 54))){
    		alert("Error no:1207 We are Extremely Sorry,\nThis is not Zip code\nPlease Reinsert Zip Code\nThank you.");
    		textbox.focus();
    	} else{
    		return true;
    	}
    }
    Thank you,
    -Anurag
    Last edited by DeadMeatGF; 05-14-2007 at 03:30 AM. Reason: VJ Added code tags - DM Indented code

  2. #2
    vinyl-junkie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    721

    Re: Need help How one can use substr (); function with numeric value.

    The easiest way to validate a zip code is using regular expressions. Here is some code that does it that way.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more



Tags for this Thread