if (document.formName.textName.length < "3") { alert("Invalid area code") } is that what you're looking for?