I've been trying to create a regular expression to validate a string, but since this is my first time with regular expressions, I'm making very hard work of it.
The accepted string format is NNNNAA where N=numberic and A=Alpha. The field is forced uppercase.
I can validate the NNNN part but can't work out how to also check the AA part.
Here's what I have so far:
<Sctipt Language="JavaScript">
function check(){
var rExp=/^\d{4}$/ //Allowed NNNNAA
if (document.myForm.inputField.value.search(rExp)==-1){ //if match failed
alert('Invalid')
}else{
alert('Ok')
}
}
</Script>
<form name="myForm" method="post">
<input type="text" name="inputField" value="" onBlur="check()" size="6" maxlength="6">
</form>
Can anyone offer any assistance.
Thanks.
Kevin.
The accepted string format is NNNNAA where N=numberic and A=Alpha. The field is forced uppercase.
I can validate the NNNN part but can't work out how to also check the AA part.
Here's what I have so far:
<Sctipt Language="JavaScript">
function check(){
var rExp=/^\d{4}$/ //Allowed NNNNAA
if (document.myForm.inputField.value.search(rExp)==-1){ //if match failed
alert('Invalid')
}else{
alert('Ok')
}
}
</Script>
<form name="myForm" method="post">
<input type="text" name="inputField" value="" onBlur="check()" size="6" maxlength="6">
</form>
Can anyone offer any assistance.
Thanks.
Kevin.