Hey guys,
Name input value should be entered as shown on credit card eg. 'John P Smith'. I'm trying to prevent 'Aaaaa B Ccccccc' being sent to the sever. Any suggestions appreciated. I'm pritty sure the var rep=regex is causing the script to hang on the first if it acctualy finds the lowercase repeated more than 2times and I realy need to check that lowercase isn't repeated sequentialy more than 2 times?
THE HTML
<p id="reply">Please enter your name as shown on credit card.</p>
<input type="text" id="name" name="name" class="required" value=" " \>
THE SCRIPT
//namechange function
function namechange()
{
var n=name.value;
n.split(' ').join(''); //get rid of extra white space;
var names=new Array();
names=n.split(' '); //set array delimeter ' ' to space
var first=names[0]; //also tried var first=names.slice(0,1);
var middle=names[1]; //also tried var middle=names.slice(1,2);
var last=names[2]; //also tried var last=names.slice(2,3);
var rep=/^[a-z].{3}$/; //if lowercase alpha repeated 3 times word isn't name need sequential regex!
if(names.length<3) //check that input isn't less than 3 words long ie. 'John P Smith'='John Smith'
{
reply.innerHTML='Your name must be 3 words long eg. John P Smith.';
name.value='Error!'; //lower case 'r' repeated 3 times?
name.style.color='red';
return:false;
}
if(names.length>3) //make sure input value not 'John P Smith Jr'
{
reply.innerHTML='Your name must be 3 words long eg. John P Smith.';
name.value='Error!'; //lower case 'r' repeated 3 times?
name.style.color='red';
return:false;
}
if(first.match(rep)) //check that lowercase not repeated 3 times should be sequential?
//once this gets picked up the reply remains the same onchange even if 'John P Smith' is entered?!!
reply.innerHTML='This is not a real name: '+first+'.';//ie. not 'Joooohn'
name.value='Error!'; //lower case 'r' repeated 3 times?
name.style.color='red';
return:false;
}
if(middle.length>=1) // Make sure middle is initialized ie. not 'John Paul Smith' works on it's own
{
reply.innerHTML='Please initialize your middle name '+middle+' eg. John P Smith.';
name.value='Error!'; //lower case 'r' repeated 3 times?
name.style.color='red';
return:false;
}
if(last.match(rep)) //check last for repetive lowercase should be sequential?
//if caught 'John P Smmmmith' reply returns 'This is not a real firstname: '+first+'.'??
{
reply.innerHTML='This is not a real last name: '+last+'. '; //ie. not 'Smmmmith'
name.value='Error!'; //lower case 'r' repeated 3 times?
name.style.color='red';
return:false;
}
else
{
reply.innerHTML='Thank you '+name.value+', card verification pending.';
name.style.color='blue';
return:true;
}
}
Yeah my javascript is getting better but my regex applied script sucks.:@:$