473,378 Members | 1,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Advanced server-side form validation

Can anybody point me to a good tutorial/manual on advanced server-side
form validation including validation of fields against unwanted
strings such as the use of "http://".

Thank you in advance,

FayeC
Jul 15 '06 #1
2 2356

FayeC wrote:
Can anybody point me to a good tutorial/manual on advanced server-side
form validation including validation of fields against unwanted
strings such as the use of "http://".

Thank you in advance,
You can go two ways with this kind of thing, depending on how complex
your validation is and what action you want to take as a result of
invalid data. Your example is straightfoward. Use of instr against
the string will find whether something like "http://" is in there.
Most of these tasks can be accomplished using the built-in functions.
More complex tasks might benefit from the use of Regular Expressions.

http://msdn.microsoft.com/library/de...ting051099.asp

--
Mike Brind

Jul 15 '06 #2
On Sat, 15 Jul 2006 16:49:30 -0500, FayeC <fa*******@hotmail.comwrote:
Can anybody point me to a good tutorial/manual on advanced server-side
form validation including validation of fields against unwanted
strings such as the use of "http://".
I have no specific references to direct you to, but I tend to create a
class for each form that has one method which reads the form data from a
collection (usually one of either the QueryString or Form properties of
the Request object), and a second that returns True if the data is
valid. The form data itself is exposed as properties, and there is
usually a collection of error messages that is populated by the
validation method. Even if you never use the form in more than one
place, it's nice to get all the form processing code out of the main
flow of the page.

A quick 'n dirty (and rather obnoxious) new account form using this
style follows.

Class NewAccountForm
Public UserName
Public Password1
Public Password2
Public Email
Public WhatNumberAmIThinkingOf

Public Messages

Function Init(form)
UserName = Trim(form("username"))
Password1 = Trim(form("password1"))
Password2 = Trim(form("password2"))
Email = Trim(form("email"))

WhatNumberAmIThinkingOf = form("whatnumberamithinkingof")
If IsNumeric(WhatNumberAmIThinkingOf) Then
WhatNumberAmIThinkingOf = CLng(WhatNumberAmIThinkingOf)
Else
WhatNumberAmIThinkingOf = 0
End If

Set Init = Me
End Function

Function DataValid()
DataValid = True

If Len(UserName) = 0 Then
Messages("username") = "Please enter a username."
DataValid = False
End If

If Len(Password1) = 0 Then
Messages("password1") = "Please enter password."
DataValid = False
ElseIf Password1 <Password2
Messages("password1") = "Passwords do not match."
DataValid = False
End If

If Len(Email) = 0 Then
Messages("email") = "Please enter an email address."
DataValid = False
ElseIf InStr(Email, "@") = 0 Or InStr(Email, ".") = 0 Then
Messages("email") = "Please enter a valid email address"
DataValid = False
End If

If WhatNumberAmIThinkingOf <5 Then
Messages("whatnumberamithinkingof") = "Ha! Nice try, buddy!"
DataValid = False
End If
End Function

Private Sub Class_Initialize
Set Messages = CreateObject("Scripting.Dictionary")
End Sub
End Class

--
Justin Piper
Bizco Technologies
http://www.bizco.com/
Jul 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Michael J. Wendell | last post by:
Hello, I am trying to debug an issue with sessions in my ASP 3.0 web application, which runs fine on WIN2K Pro and WINXP Pro, yet fails to function correctly on WIN2K Advanced Server. My actual...
1
by: Barb | last post by:
What is the limitation of memory that SQL Server 2000 Standard can use when running on a Windows 2000 Advanced Server platform?
3
by: ChrisL | last post by:
I currently have two SQL server books for MS SQL Server 2000. One is a prep book for the 70-229 exam, the other is a Wrox book: "professional SQL Server 2000 Programming." I'm looking for more...
6
by: abhishekjha10 | last post by:
i was asked this question in an interview. the question is that " what do u mean by advanced architecture of c++" i was unable to answer. what can be the answer ?
0
by: Just D. | last post by:
All, What's the easiest way to create a Virtual Directory with required properties like: 1) delete all Start File names but insert only one required 2) one of the sub Directories should be...
1
by: mosscliffe | last post by:
I wanted to install the SQL SERVER 2005 Express Advanced Services, because I wanted the import / export features of the data manager. I chose the route of deleting the template files and then...
1
by: Parv | last post by:
I am trying to impersonate user to some other system using userName,domainName,password in C#. My Code is working fine if i am working on Windows 2000 professional after assigning current user "Act...
3
by: | last post by:
I'm planning to transport a desktop application to the web. A spin-off of this application has already been put on the web by another programmer. He used ColdFusion with MS SQL, Access, VC, and...
2
by: rajendrsedhain | last post by:
Hi, I have 1 checkboxlist, 5 dropdownlits and three textboxes.I have to write the SQL query and c# code for that advanced search. <asp:CheckBoxList ID="reposotoryCheckBoxList" runat="server"...
1
by: BobLewiston | last post by:
I installed SQL Server 2008 Express, basic edition (SQLEXPR32_x86_ENU_Bootstrapper.exe, version 9.0.30729.1) without any problem. Then I attempted to install AdventureWorks Sample Databases for...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.