Jump to content

Error's on page question?


Solarpitch

Recommended Posts

When a web page loads and you see "Error on page" bottom left, can that affect the way in which Javascript functions are preformed? I have a basic validation function that I am trying to implement from:

http://developer.apple.com/internet/webcontent/validation.html

The code doesnt seem to work however. I tried pasting everything into the page and using the external validate.js file called via src = "" but still no joy.

I seem to have a few errors on my page regarding the height attribute not been compatible with IE 5+ and so on. Could these css error be preventing the validation from working or is their something in the code that needs to be changed?

I currently have the code as follows:

[code]

// Register.php - I have the main check function that is calling the sub functions in validate.js (src = "validate")

function checkWholeForm(theForm) {
    var why = "";
    why += checkEmail(theForm.email.value);
    why += checkPhone(theForm.phone.value);
    why += checkPassword(theForm.password.value);
    why += checkUsername(theForm.username.value);
    why += isEmpty(theForm.notempty.value);
    why += isDifferent(theForm.different.value);
    for (i=0, n=theForm.radios.length; i<n; i++) {
        if (theForm.radios[i].checked) {
            var checkvalue = theForm.radios[i].value;
            break;
        }
    }
    why += checkRadio(checkvalue);
    why += checkDropdown(theForm.choose.selectedIndex);
    if (why != "") {
      alert(why);
      return false;
    }
return true;
}

// and I have the usual ... action = "Process_Registration" OnSubmit = "return checkWholeForm(theForm)"

[/code]


[code]

// Validate.js - sub functions


// email

function checkEmail (strng) {
var error="";
if (strng == "") {
  error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) {
      error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
      var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
        if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
      }
    }
return error;   
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
var error = "";
if (strng == "") {
  error = "You didn't enter a phone number.\n";
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
      error = "The phone number contains illegal characters.";
 
    }
    if (!(stripped.length == 10)) {
error = "The phone number is the wrong length. Make sure you included an area code.\n";
    }
return error;
}


// password - between 6-8 chars, uppercase, lowercase, and numeral

function checkPassword (strng) {
var error = "";
if (strng == "") {
  error = "You didn't enter a password.\n";
}

    var illegalChars = /[\W_]/; // allow only letters and numbers
   
    if ((strng.length < 6) || (strng.length > 8)) {
      error = "The password is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\n";
    }
    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
      error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    } 
return error;   
}   


// username - 4-10 chars, uc, lc, and underscore only.

function checkUsername (strng) {
var error = "";
if (strng == "") {
  error = "You didn't enter a username.\n";
}


    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 4) || (strng.length > 10)) {
      error = "The username is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "The username contains illegal characters.\n";
    }
return error;
}     


// non-empty textbox

function isEmpty(strng) {
var error = "";
  if (strng.length == 0) {
    error = "The mandatory text area has not been filled in.\n"
  }
return error;  
}

// was textbox altered

function isDifferent(strng) {
var error = "";
  if (strng != "Can\'t touch this!") {
    error = "You altered the inviolate text area.\n";
  }
return error;
}

// exactly one radio button is chosen

function checkRadio(checkvalue) {
var error = "";
  if (!(checkvalue)) {
      error = "Please check a radio button.\n";
    }
return error;
}

// valid selector from dropdown list

function checkDropdown(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose an option from the drop-down list.\n";
    }   
return error;
}   

[/code]


Anyway, when submit is clicked no validation occurs at all and the Process_Registration paged is executed.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.