Hallo,
ich habe ein Problem.
Ich habe eine Postleitzahlenabfrage und muss ausschließen, dass die Abfrage 00000 durchgeht. Es soll die Fehlermeldung kommen 00000 ist keine gültige Postleitzahl.
Hier das Script:
<script language="JavaScript">
function chkFormular() {
var chkZ = 1;
for(i=1;i<document.Formular.PLZ.value.length;++i)
if(document.Formular.PLZ.value.charAt(i) < "0"
|| document.Formular.PLZ.value.charAt(i) > "9")
chkZ = -1;
if(chkZ == -1)
{
alert(document.Formular.PLZ.value + " ist keine gültige PLZ.")
document.Formular.PLZ.focus();
return false;
}
if(document.Formular.PLZ.value.length != 5)
{
alert(document.Formular.PLZ.value + " ist keine fünfstellige PLZ.")
return false;
}Ich habe mal versucht diese Zeile einzufügen, doch er sagt mir logischerweise das keine PLZ gültig ist.
if(document.Formular.PLZ.value = 00000)
{
alert(document.Formular.PLZ.value + " ist keine gültige PLZ.")
return false;
}
}
</script>
Hat irgendjemand eine Lösung?
Marco
Ist denn 00001 und 01000 eine gültige PLZ? Meiner Meinung nach sollte hier eine Prüfung nach völligem Quatsch reichen. Wie :
<html>
<head>
<title></title>
<script language="JavaScript">
<!--
function isPLZ(str) {
var is = false;
if (str.length==5)
if (str.match(/\b\d\d\d\d\d\b/)) is=true;
return is;
}
//-->
</script>
<noscript></noscript>
</head>
<body >
<form name="adr" onSubmit="alert(isPLZ(this.plz.value));">
<input type="Text" name="plz" value="" size="" maxlength="">
<input type="Submit" name="OK" value="OK">
</form>
</body>
</html>
Gruß
Axel