Sandy Barnabas received a rather odd message when submitting a registration form:

 

 

Sandy looked at the Last Name field and verified that "Barnabas" was, in fact, typed in correctly. He tried again, only to get the same error message. Thinking that the website knew something he didn't, Sandy took a quick peek at her passport: yep, "Barnabas" was, in fact, her last name. So, he took a peek at the form's source ...

//8/9  
// - ADD better lead JS filters (TBK)
// - Require a minimum of two characters for first name and last name
// - Reject first or last names that contain more than two consecutive 
//   entries of the same character, e.g. ooo, lll, eee, etc.
// - Reject first or last names containing the string “asdf”

if( has_firstname && has_lastname ) 
{
    var firstname = eval('object.firstname.value');
    var lastname = eval('object.lastname.value');
    firstname = firstname.toLowerCase();
    lastname = lastname.toLowerCase();
    
    if( lastname.length < 2 ) {
        alert("Please enter a valid Last Name.");
        eval('object.lastname.focus()');
        return false;
    }
    if( firstname.length < 2 ) {
        alert("Please enter a valid First Name.");
        eval('object.firstname.focus()');
        return false;
    }

    if( lastname.indexOf('asdf') != -1 ) {
        alert("Please enter a valid Last Name.");
        eval('object.lastname.focus()');
        return false;
    }
    if( firstname.indexOf('asdf') != -1 ) {
        alert("Please enter a valid First Name.");
        eval('object.firstname.focus()');
        return false;
    }

    for( i = 0; i < firstname.length; i++ ) {
      var substrings = firstname.split(firstname.charAt(i));
      if(substrings.length - 1 >= 3) {
        alert("Please enter a valid First Name.");
        eval('object.firstname.focus()');
        return false;      
      }
    }
    for( i = 0; i < lastname.length; i++ ) {
      var substrings = lastname.split(lastname.charAt(i));
      if(substrings.length - 1 >= 3) {
        alert("Please enter a valid Last Name.");
        eval('object.lastname.focus()');
        return false;      
      }
    }
  }
  
	return true;
} // function validation END

Sandy adds: "The only problem is that it rejects all last or first names with more than 3 of the same character, regardless of if they are consecutive or not. So I guess my last name isn't valid enough to sign up for this awesome site."

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!