mixelplik
03-21-2009, 09:51 PM
This is driving me bonkers. I want the user to enter the first and last name in a text field, it will only accept the entry is there are no spaces at the end or begining of the entry and at least one in the middle. This was tricky as I'm a newb, but then I added the part that makes sure only letters were added (supposed to be the easy part) and the whole thing went kerplunk, I know there's a conflict somewhere, just not knowlageable enough to figure out where, can any one help? :confused:
Here's my code:
function nm(){
var name = document.getElementById('text').value;
var leng = name.length - 1;
if(name == "" || name.indexOf(" ") == 0 || name.lastIndexOf(" ") == leng || name.match(" ") == null || name.match(/[^a-zA-Z]/)) {
alert('enter a first and a last name');
}else{
document.getElementById("name").innerHTML = name;
}
}
Like I said, everything worked fine until I added the name.match[^a-zA-z] bit. Thanks in advance for any help yo!
Here's my code:
function nm(){
var name = document.getElementById('text').value;
var leng = name.length - 1;
if(name == "" || name.indexOf(" ") == 0 || name.lastIndexOf(" ") == leng || name.match(" ") == null || name.match(/[^a-zA-Z]/)) {
alert('enter a first and a last name');
}else{
document.getElementById("name").innerHTML = name;
}
}
Like I said, everything worked fine until I added the name.match[^a-zA-z] bit. Thanks in advance for any help yo!