The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Javascript Validation troubles

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
  • #26848

    I’m a uni student studying web development, normally I don’t do much javascript but it’s necessary to pass the module so I’m learn what I can, and to me fair learning it even if it isn’t necessary is a good idea in my opinion. Anyway we’ve been given a piece of code that checks if you Post code is local or not (post codes are the equivalent of Zipcodes in the UK) each one starts with two letters and the javascript searches the form information you’ve submitted using the substring property to find if those two letters are the same as the two letters for the local postcode.

    We have been constructed to modify the code so that it will search for an @ sign in an email field and send an alert if it doesn’t have one. So far I’ve managed to get it to recognize the @ but only if its the only character in the box. I’ve tried numerous things to get it to look through the whole code but to no avail.

    I will post my code as it is at this point plus the original code. If it’s not to much trouble I would prefer if you explained how to fix it rather than just posting the fixed code, otherwise it would defeat the point of doing the assignment in the first place.

    My code:
    function validate() {
    email =;
    email = email.toLowerCase();
    if (email.substring(0,25) != "@") {alert ("Invalid Email"); return false;}
    else return true;

    Original code:
    function validate() {
    userpc = document.thisForm.postcode.value;
    userpc = userpc.toLowerCase();
    if (userpc.substring(0,2) != "pl") return false;
    else return true;

Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.