Help with javacript field check

Discussion in 'HTML & Website Design' started by stricksurfer, Jan 29, 2009.

  1. #1
    How do I check an entry field in my form called affiliatecode to make sure it has the string "register.i-say.com" somewhere in it?
     
    stricksurfer, Jan 29, 2009 IP
  2. Website Design Perth

    Website Design Perth Peon

    Messages:
    66
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This js (external file) may help point you in the right direction - see the last part where it checks for an @ in the email address:

    function validateForm(theform) {
     for (var i=0; i<theform.elements.length; i++) {
      var element = theform.elements[i];
      if (element.className.indexOf("required") !=-1) {
       element.className = "required";
       if (!isFilled(element)) {
        alert("Please enter your " +element.id);
        element.className += " input";
        element.focus();
        return false;
       } 
      }
      if (element.className.indexOf("email") !=-1) {
       element.className = "email";
       if (!isEmail(element)) {
        alert("Please check you have entered a valid email address");
        element.className += " input";
        element.focus();
        return false;
       }
      }
     }
     return true;
    }
    
    function isFilled(field) {
     if (field.value.length < 1) {
      return false;
     } else {
      return true;
     }
    }
    function isEmail(field) {
     if (field.value.indexOf("@") == -1 || field.value.indexOf(".") == -1) {
      return false;
     } else {
      return true;
     }
    }
    Code (markup):
     
    Website Design Perth, Jan 31, 2009 IP