 <p>Use <code>RegExpTxt.test(Fname.value)</code> instead of <code>RegExpTxt(Fname.value)</code></p> <p>Javascript should end up being:</p> <pre><code>function form_onchange(){ var Fname = document.getElementById('Fname'); var RegExpTxt = /^([a-zA-Z ]){2,30}$/; if (!RegExpTxt.test(Fname.value)) { alert('Please provide a valid name'); Fname.focus(); Fname.select(); return false; } } </code></pre>