|
The following code examples are free for you to use for your personal web projects, but may not be sold or distributed on another website without the permission of WebHostingWit.com.
Date/Time Greeter
By using the Date and Datepart functions, we can build a small section of code for greeting people with different messages depending on the date or the time.
|
|
|
|
<%
Dim hourget
Select Case (Left(Date,5))
Case "12/25"
Response.Write ("Merry Christmas!")
Case "07/04"
Response.Write ("Happy Independence Day!")
Case "01/01"
Response.Write ("Happy New Year!")
Case "02/14"
Response.Write ("Happy Valentine's Day!")
Case Else
hourget = Datepart("H",date)
If hourget < 12 Then
Response.Write ("Good Morning! It's " & Datepart("H",Date") & ":" & DatePart("N",date"))
Else
If hourget > 11 And hourget < 18 Then
Response.Write ("Good Afternoon! It's " & Datepart("M",Date") & "/" & DatePart("D",date"))
Else
Response.Write ("Good Evening! Date and Time: " & Date)
End If
End If
End Select
%> |
|
|
|
Form Validator
To validate a form, you'll need to have the <form> tag in your html point to the asp page that will validate your code. For example:
|
|
|
|
<form method="post" action="validate.asp"> |
|
|
|
Now you'll need to create a new page called validate.asp and use the following code. Remember to change the form names to match those in your code, and to replace file.html with the form file name. In here we only check for a valid e-mail address, and make sure the first name, last name, and phone number are filled in.
|
|
|
|
<%@ language=vbscript %>
<%
option explicit
if session("verify") <> "" then
%>
<html>
<body>
<!-- Put any customized html anywhere inside here -->
<%=session("verify")%><br><br>
<a href="file.html">Click here to return to the form file.</a>
</body>
</html>
<%
session("verify") = ""
end if
if len(request.form("firstname")) = 0 then
session("verify") = "Please include your first name."
response.redirect("validate.asp")
end if
if len(request.form("lastname")) = 0 then
session("verify") = "Please include your last name."
response.redirect("validate.asp")
end if
if len(request.form("phonenumber")) = 0 then
session("verify") = "Please include your phone number."
response.redirect("validate.asp")
end if
if ubound(split(lcase(request.form("email")),"@",2,1)) < 1 or ubound(split(lcase(ubound(split(lcase(request.form("email")),"@",2,1)))),".",-1,1)) < 1 then
session("verify") = "Please use a valid e-mail address."
response.redirect("validate.asp")
end if
%> |
|
|
|
©2003 Web Hosting Wit.Com and its licensors. All Rights Reserved
Designed by Fencl Web Design
|