jk296
Mitglied
Registriert: 28.02.2007
Beiträge: 22
|
|
Also,
dieser Artikel (aktuell.de.selfhtml.org/artikel/javascript/email-check/index.htm) ist ja gut und schön, allerdings kriege ich das Script in mein Projekt nicht integriert:
1.: Die Scripts stehen in einer externen Datei (.js). Darin soll auch das Script zur Überprüfung der E-Mail-Syntax stehen.
2.: Habe in der Script-Datei schon die Funktion chkFormular (aus Artikel "Formulareingaben überprüfen") mit den Anweisungen
if (document.Formular.User.value == "") { alert("Bitte Ihren Namen eingeben!"); document.Formular.User.focus(); return false; }
if (document.Formular.Ort.value == "") { alert("Bitte Ihren Wohnort eingeben!"); document.Formular.Ort.focus(); return false; }
if (document.Formular.Alter.value == "") { alert("Bitte Ihr Alter eingeben!"); document.Formular.Alter.focus(); return false; }
usw.
Die Anweisungen in der Checkfunktion zur Überprüfung der E-Mail-Syntax (function checkForm) sollen jetzt in die Funktion chkFormular integriert werden, also mit if (document.Formular.mail usw.
Kriege das beides nicht hin und bitte um Hilfen.
|
|
| 20.03.2008 15:52:15 |
|
HTMELL
Administrator
Registriert: 11.05.2006
Beiträge: 543
|
|
Hi, etwa so?
Code:
if(document.Formular.email.value == "") {
alert("Bitte Ihr Email-Adresse eingeben!");
document.Formular.email.focus();
return false;
}
else {
checkEmail(document.Formular.email.value, false);
} |
_______________________________________ mfg Thomas Mell
www.validome.org
|
|
| 20.03.2008 18:14:46 |
|
dkdenz
Administrator
Ort: Lübeck
Registriert: 25.04.2005
Beiträge: 605
|
|
Hi Einen Formcheck mittels JavaSript zu vollziehen, empfinde ich zumindest als suboptimal. Besser wäre eine PHP-Lösung, denn nicht jeder User hat JS aktiviert. Viel Spaß noch...
_______________________________________ Mozilla/5.0 (X11; U; Linux i686; de; rv:1.8.0.14eol) Gecko/20080418 Ubuntu/dapper-security Firefox/1.5.0.12eol
|
|
| 20.03.2008 20:58:29 |
| http://dkmd.de | http://dkdenz.de |
Zitieren |
|
jk296
Mitglied
Registriert: 28.02.2007
Beiträge: 22
|
|
Habe das stehen:
Code:
function isDigit( ch )
{
if ( (ch >= '0') && (ch <= '9') )
return true;
else
return false;
}
function isAlpha( ch )
{
if ( ((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')) )
return true;
else
return false;
}
function isAlnum( ch )
{
if ( isAlpha( ch ) || isDigit( ch ) )
return true;
else
return false;
}
function notIn( str1, str2 )
{
var i = 0;
var j = str2.length;
for( ; i<j; i++ )
{
var str3 = str2.charAt(i);
if( str1.indexOf( str3 ) != -1 )
return false;
}
return true;
}
function checkUsername( username, mustBeQuoted )
{
var i = 0;
var j = username.length;
if ( username.charAt(0) != '"' )
{
if ( (username.charAt(0) < ' ') || (username.charAt(0) > '~')
|| !notIn( mustBeQuoted, username.charAt(0) ) )
return false;
for( i=1; i<j; i++ )
{
if ( ( (username.charAt(i) < ' ') || (username.charAt(i) > '~')
|| !notIn ( mustBeQuoted, username.charAt(i) ) )
&& ( username.charAt(i-1) != '\\' ) )
return false;
}
}
else
{
if ( username.charAt( j-1 ) != '"' )
return false;
for( i=1; i<j-1; i++ )
{
if ( ( (username.charAt(i) == '\n') || (username.charAt(i) == '\r')
|| (username.charAt(i) == '\"') )
&& (username.charAt(i-1) != '\\') )
return false;
}
}
return true;
}
function checkNr ( nr )
{
var i=0;
var j=nr.length;
if( j < 1 )
return false;
for( ; i<j; i++ )
if( ( nr.charAt(i) < '0' ) || ( nr.charAt(i) > '9' ) )
return false;
return true;
}
function checkIpnr( ipnr )
{
var iL=0;
var iC=0;
var i=0;
var sNr = "";
for( ; i< ipnr.length; i++ )
{
if ( ipnr.charAt(i) == '.' )
{
if ( !iL || (iL> 3) || parseInt( sNr,10 ) > 255 )
return false;
iC++;
iL = 0;
sNr = "";
continue;
}
if ( isDigit ( ipnr.charAt(i) ) )
{
iL++;
sNr = sNr + ipnr.charAt(i);
continue;
}
return false;
}
if ( parseInt( sNr,10 ) > 255 )
return false;
if ( ( (iC==3) && (iL>=1) && (iL<=3) ) || ( (iC==4) && (!iL) ) )
return true;
else
return false;
}
function checkFqdn( fqdn )
{
var iL=0;
var iC=0;
var i=fqdn.length-1;
if ( (fqdn.charAt(0) == '.') || (fqdn.charAt(0) == '-') )
return false;
if ( fqdn.charAt(i) == '.' )
i=i-1;
for( ; i>=0; i-- )
{
if ( fqdn.charAt(i) == '.' )
{
if ( iL < 2 && iC < 2 )
return false;
if ( fqdn.charAt(i-1) == '-' )
return false;
iC++;
iL = 0;
continue;
}
if ( isAlnum ( fqdn.charAt(i) ) )
{
iL++;
continue;
}
if ( fqdn.charAt(i) == '-' )
{
if ( !iL )
return false;
iL++;
continue;
}
return false;
}
if ( !iC || ( iL == 1 && iC < 2 ) || ( !iL && iC==1 ) ) {
return false;
}
return true;
}
function checkHostname( hostname )
{
if ( hostname.charAt(0) == '[' )
{
if ( hostname.charAt(hostname.length-1) != ']' )
return false;
var ipnr = hostname.substring( 1, hostname.length -1 );
return checkIpnr( ipnr );
}
if ( hostname.charAt(0) == '#' )
{
var nr = hostname.substring( 1, hostname.length );
return checkNr( nr );
}
return checkFqdn( hostname );
}
function checkEmailAdr( address )
{
var status = true;
var username = "";
var hostname = "";
if ( address.length < 8 )
return false;
var seperate = address.lastIndexOf("@");
if ( seperate == -1 )
return false;
username = address.substring(0, seperate );
if ( ! checkUsername( username, "<>()[],;:@\" " ) )
return false;
hostname = address.substring(seperate+1, address.length );
if ( ! checkHostname( hostname ) )
return false;
return true;
}
function checkEmail( email, allowFullname )
{
var existFullname = false;
var status = true;
var fullname = "";
var adress = "";
if ( email.length < 8 )
return false;
var emailBegin = email.indexOf("<");
var emailEnd = email.lastIndexOf(">");
if ( (emailBegin == -1) && (emailEnd == -1) )
return checkEmailAdr( email );
if ( ( (emailBegin == -1) && (emailEnd != -1) )
|| ( (emailBegin != -1) && (emailEnd == -1) ) )
return false;
adress = email.substring( emailBegin+1, emailEnd );
if ( ! checkEmailAdr( adress ) )
return false;
if ( email.length == adress.length + 2 )
return true;
else
if ( ! allowFullname )
return false;
if ( emailEnd == email.length - 1 )
{
if ( emailBegin == 0 )
return true;
if ( email.charAt( emailBegin -1 ) != ' ' )
return false;
fullname = email.substring( 0, emailBegin-1 );
return checkUsername ( fullname, "<>()[],;:@\"" );
}
return false ;
} |
und darunter
Code:
if(document.Formular.email.value == "") {
alert("Bitte Ihr Email-Adresse eingeben!");
document.Formular.email.focus();
return false;
}
else {
checkEmail(document.Formular.email.value, false);
} |
Wenn ich keine Adresse eingegeben habe, dann meckert er (richtigerweise). Wenn ich aber eine inkorrekte Adresse eingegeben habe, etwa 12345@12345,12345 (so, wie es laut Bedingungen nicht sein soll), dann erkennt er das einfach an und springt ins nächste Feld!? (Es sollen keine Extra-Fehlermeldungen erfolgen.)
|
|
| 21.03.2008 22:02:24 |
|
jk296
Mitglied
Registriert: 28.02.2007
Beiträge: 22
|
|
Mehnno!!! Das geht nicht!
Habe eine js-Datei mit diesen Anweisungen (de.selfhtml.org/javascript/beispiele/formulareingaben.htm):
Code:
function chkFormular () {
if (document.Formular.User.value == "") {
alert("Bitte Ihren Namen eingeben!");
document.Formular.User.focus();
return false;
}
if (document.Formular.Ort.value == "") {
alert("Bitte Ihren Wohnort eingeben!");
document.Formular.Ort.focus();
return false;
}
if (document.Formular.Alter.value == "") {
alert("Bitte Ihr Alter eingeben!");
document.Formular.Alter.focus();
return false;
}
var chkZ = 1;
for (i = 0; i < document.Formular.Alter.value.length; ++i)
if (document.Formular.Alter.value.charAt(i) < "0" ||
document.Formular.Alter.value.charAt(i) > "9")
chkZ = -1;
if (chkZ == -1) {
alert("Altersangabe keine Zahl!");
document.Formular.Alter.focus();
return false;
}
} |
Jetzt soll das Script zur Überprüfung der E-Mail-Syntax (aktuell.de.selfhtml.org/artikel/javascript/email-check/index.htm) in die Datei integriert werden, und zwar mit der vorausgehenden Anweisung
Code:
if (document.Formular.Mail.value == "") {
alert("Bitte Ihre E-Mail-Adresse eingeben!");
document.Formular.Mail.focus();
return false;
} |
(alles nach Überprüfung des Alters). Dabei soll eben die
Code:
function checkForm( form ) |
zur
Code:
function chkFormular |
aufgelöst werden, und zwar zum einen formell so wie bei den anderen Prüfpunkten (User, Ort, ...) mit. evtl. Zurückspringen ins Feld, zum anderen entweder mit der Fehlermeldung "Bitte Ihre E-Mail-Adresse eingeben!" (keine E-Mail-Adresse eingegeben) oder mit der Fehlermeldung "Inkorrekte E-Mail-Adresse" (zwar E-Mail-Adresse eingegeben, aber eine inkorrekte).Und was bitte hat die Stelle
Code:
<SCRIPT language="JavaScript1.1">
<!--
var js11=true;
//-->
</SCRIPT> |
zu bedeuten?
Beitrag geändert von jk296 (26.03.2008 20:10:23)
|
|
| 26.03.2008 20:09:52 |
|
Chiaki
Mitglied
Ort: Germany (81825)
Registriert: 23.12.2007
Beiträge: 95
|
|
Hallo,
ich weis nicht, welches Problem genau du mit den Scripts hast, bei mir funktioniert es im IE 7 und im FF 2.0.0.12 wie gewünscht und gedacht.
>> Datei: checkform.js
Code:
function checkForm() {
if(document.getElementById('username').value == "") {
alert("Bitte Ihren Namen eingeben!");
document.getElementById('username').focus();
return false;
}
if(document.getElementById('wohnort').value == "") {
alert("Bitte Ihren Wohnort eingeben!");
document.getElementById('wohnort').focus();
return false;
}
if(document.getElementById('alter').value == "") {
alert("Bitte Ihr Alter eingeben!");
document.getElementById('alter').focus();
return false;
}
if(document.getElementById('email').value == "") {
alert("Bitte Ihre E-Mail-Adresse eingeben!");
document.getElementById('email').focus();
return false;
}
if(!checkEmail(document.getElementById('email').value,false)) {
alert("Bitte geben Sie eine korrekte E-Mail-Adresse ein!");
document.getElementById('email').focus();
return false;
}
}
function isDigit( ch )
{
if ( (ch >= '0') && (ch <= '9') )
return true;
else
return false;
}
function isAlpha( ch )
{
if ( ((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')) )
return true;
else
return false;
}
function isAlnum( ch )
{
if ( isAlpha( ch ) || isDigit( ch ) )
return true;
else
return false;
}
function notIn( str1, str2 )
{
var i = 0;
var j = str2.length;
for( ; i<j; i++ )
{
var str3 = str2.charAt(i);
if( str1.indexOf( str3 ) != -1 )
return false;
}
return true;
}
function checkUsername( username, mustBeQuoted )
{
var i = 0;
var j = username.length;
if ( username.charAt(0) != '"' )
{
if ( (username.charAt(0) < ' ') || (username.charAt(0) > '~')
|| !notIn( mustBeQuoted, username.charAt(0) ) )
return false;
for( i=1; i<j; i++ )
{
if ( ( (username.charAt(i) < ' ') || (username.charAt(i) > '~')
|| !notIn ( mustBeQuoted, username.charAt(i) ) )
&& ( username.charAt(i-1) != '\\' ) )
return false;
}
}
else
{
if ( username.charAt( j-1 ) != '"' )
return false;
for( i=1; i<j-1; i++ )
{
if ( ( (username.charAt(i) == '\n') || (username.charAt(i) == '\r')
|| (username.charAt(i) == '\"') )
&& (username.charAt(i-1) != '\\') )
return false;
}
}
return true;
}
function checkNr ( nr )
{
var i=0;
var j=nr.length;
if( j < 1 )
return false;
for( ; i<j; i++ )
if( ( nr.charAt(i) < '0' ) || ( nr.charAt(i) > '9' ) )
return false;
return true;
}
function checkIpnr( ipnr )
{
var iL=0;
var iC=0;
var i=0;
var sNr = "";
for( ; i< ipnr.length; i++ )
{
if ( ipnr.charAt(i) == '.' )
{
if ( !iL || (iL> 3) || parseInt( sNr,10 ) > 255 )
return false;
iC++;
iL = 0;
sNr = "";
continue;
}
if ( isDigit ( ipnr.charAt(i) ) )
{
iL++;
sNr = sNr + ipnr.charAt(i);
continue;
}
return false;
}
if ( parseInt( sNr,10 ) > 255 )
return false;
if ( ( (iC==3) && (iL>=1) && (iL<=3) ) || ( (iC==4) && (!iL) ) )
return true;
else
return false;
}
function checkFqdn( fqdn )
{
var iL=0;
var iC=0;
var i=fqdn.length-1;
if ( (fqdn.charAt(0) == '.') || (fqdn.charAt(0) == '-') )
return false;
if ( fqdn.charAt(i) == '.' )
i=i-1;
for( ; i>=0; i-- )
{
if ( fqdn.charAt(i) == '.' )
{
if ( iL < 2 && iC < 2 )
return false;
if ( fqdn.charAt(i-1) == '-' )
return false;
iC++;
iL = 0;
continue;
}
if ( isAlnum ( fqdn.charAt(i) ) )
{
iL++;
continue;
}
if ( fqdn.charAt(i) == '-' )
{
if ( !iL )
return false;
iL++;
continue;
}
return false;
}
if ( !iC || ( iL == 1 && iC < 2 ) || ( !iL && iC==1 ) ) {
return false;
}
return true;
}
function checkHostname( hostname )
{
if ( hostname.charAt(0) == '[' )
{
if ( hostname.charAt(hostname.length-1) != ']' )
return false;
var ipnr = hostname.substring( 1, hostname.length -1 );
return checkIpnr( ipnr );
}
if ( hostname.charAt(0) == '#' )
{
var nr = hostname.substring( 1, hostname.length );
return checkNr( nr );
}
return checkFqdn( hostname );
}
function checkEmailAdr( address )
{
var status = true;
var username = "";
var hostname = "";
if ( address.length < 8 )
return false;
var seperate = address.lastIndexOf("@");
if ( seperate == -1 )
return false;
username = address.substring(0, seperate );
if ( ! checkUsername( username, "<>()[],;:@\" " ) )
return false;
hostname = address.substring(seperate+1, address.length );
if ( ! checkHostname( hostname ) )
return false;
return true;
}
function checkEmail( email, allowFullname )
{
var existFullname = false;
var status = true;
var fullname = "";
var adress = "";
if ( email.length < 8 )
return false;
var emailBegin = email.indexOf("<");
var emailEnd = email.lastIndexOf(">");
if ( (emailBegin == -1) && (emailEnd == -1) )
return checkEmailAdr( email );
if ( ( (emailBegin == -1) && (emailEnd != -1) )
|| ( (emailBegin != -1) && (emailEnd == -1) ) )
return false;
adress = email.substring( emailBegin+1, emailEnd );
if ( ! checkEmailAdr( adress ) )
return false;
if ( email.length == adress.length + 2 )
return true;
else
if ( ! allowFullname )
return false;
if ( emailEnd == email.length - 1 )
{
if ( emailBegin == 0 )
return true;
if ( email.charAt( emailBegin -1 ) != ' ' )
return false;
fullname = email.substring( 0, emailBegin-1 );
return checkUsername ( fullname, "<>()[],;:@\"" );
}
return false ;
} |
>> Datei: index.php
Code:
<?php
header('Content-Type: text/html; charset="utf-8"');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Language" content="de-DE">
<title>DC.NET Testseite</title>
<script src="./checkform.js" type="text/javascript"></script>
</head>
<body>
<h1>DC.NET Testseite</h1>
<hr>
<form method="post" action="" onsubmit="javascript:return checkForm();">
<p>Bitte geben Sie Ihre Daten ein.</p>
<table>
<tr>
<td><p><label for="username">Name:</label> </p></td>
<td><p><input id="username" type="text" name="username"></p></td>
</tr>
<tr>
<td><p><label for="wohnort">Wohnort:</label> </p></td>
<td><p><input id="wohnort" type="text" name="wohnort"></p></td>
</tr>
<tr>
<td><p><label for="alter">Alter:</label> </p></td>
<td><p><input id="alter" type="text" name="alter"></p></td>
</tr>
<tr>
<td><p><label for="email">E-Mail:</label> </p></td>
<td><p><input id="email" type="text" name="email"></p></td>
</tr>
</table>
<p><input type="submit" value="absenden"> <input type="reset" value="löschen"></p>
</form>
</body>
</html> |
>> Test-URL: http://dark-chiaki.net/test/00048671/
Greetings, Chiaki
Beitrag geändert von Chiaki (27.03.2008 07:55:12)
_______________________________________ Make sure You've read RFC 1855, before sending electronic mail, start Chats, posting on Newsgroups or leave any Comments. RFC 1855: Netiquette Guidelines <http://www.rfc1855.net/>
|
|
| 27.03.2008 07:51:31 |
|
jk296
Mitglied
Registriert: 28.02.2007
Beiträge: 22
|
|
Ah, ok! Jetzt funzts. Kleinere Fehler meinerseits (mir fehlen die Grundlagen in JS)! Danke.
|
|
| 27.03.2008 18:53:42 |
|
Wechsel zu
Die letzten Beiträge aus diesen Forum
|
|