Prova questo.
codice:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
function controlla(unValore) {
ereg1 = /^tmp[0-9]{6}$/;
ereg2 = /^[0-9]{8,11}$/;
//
if (unValore.match(ereg1)) {
//-------- matches tmp + 6 figures
//alert('ok - tmp');
return true;
} else {
if (unValore.match(ereg2)) {
//-------- matches from 8 to 11 figures
//alert('ok - 8-11');
return true;
} else {
//-------- doesnot match anything
//alert('ko');
return false;
} // if (unValore.match(ereg2))
} // if (unValore.match(ereg1))
} // function controlla(unValore)
function controllaForm() {
unValore = document.mioform.numero.value;
if (controlla(unValore)) {
//-------- controllo immissione
if (unValore.substr(0,3) == 'tmp') {
document.mioform.cod.value = 'temp';
} else {
document.mioform.cod.value = 'valido';
} // if (unValore.substr(0,3) == 'tmp')
alert( document.mioform.cod.value);
return true;
} else {
alert('Immissione scoretta\nImpossibile continuare');
return false
} // if (controlla(unValore))
} // function controllaForm()
//-->
</script>
</head>
<body>
<form name="mioform" method="post" onsubmit="return controllaForm()">
Digitare :
<input type="text" name="numero" size="13" maxlength="11">
<input type="submit" value="Submit">
<input type="hidden" name="cod"/>
</form>
</body>
</html>