Email validering
Jeg har et script der skal går ind og validering en e-mail, men hvordan for jeg det til at virke i forhold til det tekstfelt hvor man indtaster e-mailen?scriptet ser således ud:
<%
Function EmailCheck(Value, ValueMaxLength)
If (IsNull(Value)) Or (IsArray(Value)) Then Value = \"\"
If (CharPos(Value)) Or (MaxLength(Value, ValueMaxLength)) Or (CountAts(Value)) Or (IligalChars(Value)) Then
EmailCheck = False
Else
EmailCheck = True
End If
End Function
Function CharPos(Value)
If ((Instr(Value, \"@\") + 2) > InstrRev(Value, \".\")) Or (Instr(Value, \"@\") <= 1) Or (Instr(Value, \".\") <= 1) Or (InstrRev(Value, \"@\") = Len(Value)) Or (InstrRev(Value, \".\") = Len(Value)) Then
CharPos = True
Else
CharPos = False
End If
End Function
Function MaxLength(Value, ValueMaxLength)
If (Len(Value) <= ValueMaxLength) Or (ValueMaxLength = 0) Then
MaxLength = False
Else
MaxLength = True
End If
End Function
Function CountAts(Value)
AtsPos = 1
Count = 0
Do While AtsPos > 0
If Count = 0 Then AtsPos = 0
AtsPos = Instr(AtsPos+1, Value, \"@\")
If AtsPos > 0 Then Count = Count + 1
Loop
If Count <> 1 Then CountAts = True Else CountAts = False
End Function
Function IligalChars(Value)
ValueCopy = Value
LegalChars = \"abcdefghijklmnopqrstuvwxyz0123456789.@-_\"
For Counter = 1 To Len(LegalChars)
ValueCopy = Replace(ValueCopy,LCase(Mid(LegalChars,Counter,1)),\"\")
ValueCopy = Replace(ValueCopy,UCase(Mid(LegalChars,Counter,1)),\"\")
Next
If Len(ValueCopy) = 0 Then IligalChars = False Else IligalChars = True
End Function
%>
Og formen ser således ud (det er i feltet email som det scriptet foroven skal validerer):
response.write\"<table align=\"\"center\"\" width=\"\"500\"\" cellpadding=\"\"5\"\" cellspacing=\"\"0\"\"><tr><td colspan=\"\"2\"\" class=\"\"overskrift\"\">\"
response.write \"PRIS : \" & Ialt
response.write \"<form action=\"\"send.asp\"\" method=\"\"post\"\">\"
response.write \"</td><Input type=\"\"Hidden\"\" name=\"\"pris\"\" value=\" & Ialt & \"></tr><tr>\"
response.write \"<td width=\"\"150\"\" class=\"\"tekst\"\">Fornavn:</td><td width=\"\"350\"\"><input type=\"\"text\"\" name=\"\"fornavn\"\"></td></tr><tr>\"
response.write \"<td width=\"\"150\"\" class=\"\"tekst\"\">Efternavn:</td><td width=\"\"350\"\"><input type=\"\"text\"\" name=\"\"Efternavn\"\"></td></tr><tr>\"
response.write \"<td width=\"\"150\"\" class=\"\"tekst\"\">Adresse:</td><td width=\"\"350\"\"><input type=\"\"text\"\" name=\"\"Adresse\"\"></td></tr><tr>\"
response.write \"<td width=\"\"150\"\" class=\"\"tekst\"\">Postnr:</td><td width=\"\"350\"\"><input type=\"\"text\"\" name=\"\"postnr\"\" size=\"\"4\"\" maxlength=\"\"4\"\"></td></tr><tr>\"
response.write \"<td width=\"\"150\"\" class=\"\"tekst\"\">By:</td><td width=\"\"350\"\"><input type=\"\"text\"\" name=\"\"by\"\"></td></tr><tr>\"
response.write \"<td width=\"\"150\"\" class=\"\"tekst\"\">Tlf nr.:</td><td width=\"\"350\"\"><input type=\"\"text\"\" name=\"\"Tlfnr\"\" size=\"\"8\"\" maxlength=\"\"8\"\"></td></tr><tr>\"
response.write \"<td width=\"\"150\"\" class=\"\"tekst\"\">E mail:</td><td width=\"\"350\"\"><input type=\"\"text\"\" name=\"\"Email\"\"></td></tr><tr>\"
response.write \"<td width=\"\"150\"\" class=\"\"tekst\"\">Sommerkatalog</td><td width=\"\"350\"\"><input type=\"\"checkbox\"\" name=\"\"Katalog1\"\" value=\"\"Sommer\"\" checked></td></tr><tr>\"
response.write \"<td width=\"\"150\"\" class=\"\"tekst\"\">Vinterkatalog</td><td width=\"\"350\"\"><input type=\"\"checkbox\"\" name=\"\"Katalog2\"\" value=\"\"Vinter\"\" checked></td></tr><tr>\"
response.write \"<td width=\"\"150\"\" class=\"\"tekst\"\">Golfkatalog</td><td width=\"\"350\"\"><input type=\"\"checkbox\"\" name=\"\"Katalog3\"\" value=\"\"Golf\"\" checked></td></tr><tr>\"
response.write \"<td colspan=\"\"2\"\"><input type=\"\"submit\"\" name=\"\"Submit\"\" value=\"\"Send\"\"> \"
response.write \"<input type=\"\"Reset\"\"></td></tr></table>\"
response.write \"</form>\"
Altså det er mening emailen skal valideres, så man undgår fejl. men hvordan for at sammensat den 2 ting??
På forhånd TAK :))