>Findes der i ASP/javascript/vbscript en function der kan tjekke om en
streng
>er en gyldig emailadresse?
Jepp - her er en rimelig nøyaktig variant.....
<%
private function isemail(byval mailaddress)
dim tmp, x, y, berr, tmp2, objreg
dim objmatch, z, i
berr = false
tmp = trim( mailaddress )
tmp = cstr( mailaddress )
' minimum 6 characters...
if len(tmp) < 6 then
isemail = false
exit function
end if
' need an @ but only 1 is allowed
if instr(tmp, "@") then
x = instr(tmp, "@")
y = instr(x + 1, tmp, "@")
on error resume next
y = clng(y)
if err then berr = true else berr = false
on error goto 0
if berr then
isemail = false
exit function
end if
if y <> 0 then
isemail = false
exit function
end if
else
isemail = false
exit function
end if
' the "." must come after the "@"
if instr( left( tmp, clng(x) ), "." ) then
isemail = false
exit function
else
tmp2 = right( tmp, len(tmp) - clng(x) )
if instr( tmp2, "." ) then
' must have at least one character between @ and .
set objreg = new regexp
With objreg
..global = true
..ignorecase = true
..pattern = "[a-z]|[0-9]"
set objmatch = .execute(tmp2)
end With
if objmatch.count = 0 then
isemail = false
exit function
end if
set objmatch = nothing
set objreg = nothing
else
isemail = false
exit function
end if
end if
' needs to have at least 2 characters (letters) after the .
z = instr( tmp, "." )
tmp2 = right( tmp, len(tmp) - z )
set objreg = new regexp
With objreg
..global = true
..ignorecase = true
..pattern = "[a-z][a-z]"
set objmatch = .execute(tmp2)
end With
if objmatch.count = 0 then
isemail = false
exit function
end if
set objmatch = nothing
set objreg = nothing
' check for illegal characters
for i = 1 to len(tmp)
tmp2 = mid( tmp, i, 1 )
select case tmp2
case "(", ")", ";", ":", ",", "/", "'", chr(34), _
"~", "`", "!", "#", "$", "%", "^", "&", "*", _
"+", "=", "[", "]", "{", "}", "|", "\", "?", _
" ", "<", ">"
isemail = false
exit function
case else
end select
next
' if an address makes it through, it's an email address
isemail = true
end function
%>
<%
bmvalid = isemail(myemail)
if bmvalid then
' do when email is valid
end if
|