Datovalidering igen igen
Jeg har set et eksempel som erik har lavet i ASP på datovalidering:<%
function two(s)
if len(s)=1 then
two="0" & s
else
two=s
end if
end function
function datotjek(dato)
dim regex,matches,match
set regex = new regexp
regex.pattern = "^ *([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) *$"
regex.global = false
regex.ignorecase = false
set matches = regex.execute(dato)
if matches.count>0 then
set match=matches(0)
datotjek=match.submatches(0) & "-" & two(match.submatches(1)) & "-" & two(match.submatches(2))
set matches=nothing
exit function
end if
set matches=nothing
regex.pattern = "^ *([0-9]{4})([0-9]{2})([0-9]{2}) *$"
set matches = regex.execute(dato)
if matches.count>0 then
set match=matches(0)
datotjek=match.submatches(0) & "-" & two(match.submatches(1)) & "-" & two(match.submatches(2))
set matches=nothing
exit function
end if
set matches=nothing
regex.pattern = "^ *([0-9]{1,2})-([0-9]{1,2})-([0-9]{4}) *$"
set matches = regex.execute(dato)
if matches.count>0 then
set match=matches(0)
datotjek=match.submatches(2) & "-" & two(match.submatches(1)) & "-" & two(match.submatches(0))
set matches=nothing
exit function
end if
set matches=nothing
datotjek="FEJL"
end function
response.write datotjek("2004-06-01") & "<br>"
response.write datotjek(" 2004-6-1 ") & "<br>"
response.write datotjek(" 20040601 ") & "<br>"
response.write datotjek(" 1-6-2004 ") & "<br>"
response.write datotjek(" øllebrød ") & "<br>"
%>
- er der nogen der vil hjælpe mig med at omskrive det til PHP?