# HTML Form Validation

**URL:** https://forum.kirupa.com/t/html-form-validation/319350
**Category:** web dev
**Created:** [February 17, 2011, 4:32am UTC](https://forum.kirupa.com/t/html-form-validation/319350 "2011-02-17T04:32:50Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![pixel\_chick](https://avatars.discourse-cdn.com/v4/letter/p/eada6e/32.png) [@pixel\_chick](https://forum.kirupa.com/u/pixel_chick)
#### Post date: [February 17, 2011, 4:32am UTC](https://forum.kirupa.com/t/html-form-validation/319350/1 "2011-02-17T04:32:50Z")

</div>

Hello,  
I have an HTML form with some javascript error checking that looks something like this:

\<script type=‘text/javascript’\>  
function formValidator(){  
var firstname = document.getElementById(‘firstname’);  
var addr = document.getElementById(‘addr’);

```
// Check each input in the order that it appears in the form!
if(isAlphabet(firstname, "Please enter only letters for your name")){
    if(isAlphanumeric(addr, "Numbers and Letters Only for Address")){
        
    }
}
    
return false;    

```

}

function isAlphabet(elem, helperMsg){  
var alphaExp = /^[a-zA-Z]+$/;  
if(elem.value.match(alphaExp)){  
return true;  
}else{  
alert(helperMsg);  
elem.focus();  
return false;  
}  
}

function isAlphanumeric(elem, helperMsg){  
var alphaExp = /^[0-9a-zA-Z]+$/;  
if(elem.value.match(alphaExp)){  
return true;  
}else{  
alert(helperMsg);  
elem.focus();  
return false;  
}  
}  
\</script\>

\<form onsubmit=‘return formValidator()’ action=“mypage.html” method=“post” name=“myForm” \>  
First Name: \<input type=‘text’ id=‘firstname’ /\>\<br /\>  
Address: \<input type=‘text’ id=‘addr’ /\>\<br /\>  
\<input type=‘submit’ value=‘Submit’ /\>  
\</form\>

The error checking works great and throws up an alert if a field is filled out. However, once everything is filled out correctly and I hit submit, nothing happens! Can anyone help? Thank you!
