Validating a field before submitting
<p>I have a text field and a button.</p>

<p>I want to validate the field, and if the validation fails, <strong>the button should not "submit".</strong></p>

<p>This is my button: </p>

<pre><code>&lt;input type="submit"  onsubmit="return validate()"
</code></pre>

<p>And this is my validation function:</p>

<pre><code>function validate()
{
    var number = document.getElementById("temp");
    alert (number.value);

    if ( /^[0-9]{12}$/.test(number.value) ) 
    { 
        alert(number);
        return true;
    }
    alert ("מספר הפנייה חייב להיות בן 12 ספרות");
    return false; 
}
</code></pre>

<p>But it wont work, the submit occures any way.</p>

<p>Any ideas?</p>
