验证与表单中的“操作”代码冲突

I have a input text area where i want the user to enter his FULL name. So it's obligatory to have at least two word in the field.

But the validate code it's in conflict with the action code (action="nome.php") of the form.

How do i fix that?

Here is the code:

<script type="text/javascript">
// <![CDATA[
function validateMe(form_elm)
{
var full = form_elm.user.value;
// clear any spaces in front
while (full.charAt(0) == " ") full = full.substr(1);
// split and check for two names - dual purpose of also retrieving first and last name for future use
full = full.split(" ");
var first_name = full[0];
var last_name = full[1];
if (full.length < 2) alert("Please enter your full name.");
return false;
}
// ]]>
</script>

<form method="post" name="input" action="nome.php" onsubmit="return validateMe(this)">
Fazer reserva em nome de:
<input name="user" type="text"/>
<input type="submit" name="Submit" value="NEXT" />
</form>

Try trimming the whitespace from the ends of the value of the full name field, and then splitting it and checking the length of the array.

http://jsfiddle.net/bBZry/

function validate(el) {
    var text = el.user.value.trim();
    console.log(text);
    var words = text.split(" ");
    if (words.length > 1) {
     return true;   
    } else {
     return false;   
    }
}

if (!String.prototype.trim){
    String.prototype.trim = function(){
        return this.replace(/^\s+|\s+$/g,'');
    }
}