I think I can answer this one
Ok, what you need is the pattern matching powers of regular expressions (they've been quite popular here lately, search this forum for 'regular expression' and you'll see what I mean) Anyhoo. Regular expressions are specially formatted strings for pattern matching (& more, but we'll focus on the matching part now.
Ok, here's a quickie form
Code:
<form name="form1" onSubmit="return validateForm(this)"> <input type="text" name="code" /><br /> <input type="submit" name="Submit" value="Submit" /></form>
Now, in the <HEAD> of the page, we need to add some javascript, like this:
Code:
<script language="javascript">function validateForm(Frm) { var formObj = Frm.code; var codeReg = new RegExp(/^[A-Z]{2}/d*$/) if (!codeReg.test(formObj.value)) { alert("Your data is not valid for the "+formObj.name); formObj.select(); formObj.focus(); return false; } return true; }</script>Ok, so when the user submits the form the function validateForm() runs first, and returns either a TRUE or FALSE value.
Instead of exlpaining the ins and outs of regex's to you, just visit this page, as it's quite a lengthy topic
http://developer.netscape.com/docs/m...ide/regexp.htm (Thanks to Flawless_koder for the link)
Also, please visit my page that has a great (IMHO ) javascript form validator.
http://www.peterbailey.net/jsdemo