Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RE: Validation Help

Status
Not open for further replies.

dsk525

Programmer
Mar 13, 2002
73
US
Hi,

I am not experienced in validation. Could I kindly request for some help in javascript validation? I have the following fields which I would like to FORCE EACH user to fill out on the web page:

UserName, Password, FirstName, LastName, Email, LoginName, CompanyName, PhoneNumber

Any help in integrating the validation with the code below would be of tremendous help!

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
</HEAD>
<DIV ALIGN=&quot;LEFT&quot;><FONT FACE=&quot;Verdana, Arial, Helvetica, sans-serif&quot; SIZE=&quot;5&quot;><object classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot; codebase=&quot; width=&quot;228&quot; height=&quot;86&quot; id=ShockwaveFlash1>
<param name=movie value=&quot;../images/xxx_anim.swf&quot;>
<param name=quality value=high>
<embed src=&quot;../images/xxx_anim.swf&quot; quality=high pluginspage=&quot; type=&quot;application/x-shockwave-flash&quot; width=&quot;228&quot; height=&quot;86&quot;>
</embed>
</object></font>
</DIV>
<TABLE WIDTH=&quot;100%&quot; BORDER=&quot;0&quot;>
<TR>
<TD COLSPAN=&quot;3&quot; bgcolor=&quot;#CC9933&quot;><font face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;><b>Request Sent</b></font></td>
</TR>
</TABLE>
<%



Dim cnIns
Dim cmdIns
Dim strSQLStatement
Dim strUserName
Dim strPassword
Dim strFirstName
Dim strLastName
Dim strEmail
Dim strLoginName
Dim strCompanyName
Dim strPhoneNumber
Dim strFaxNumber

strUserName = Request.QueryString(&quot;UserName&quot;)
strPassword = Request.QueryString(&quot;Password&quot;)
strFirstName = Request.QueryString(&quot;FirstName&quot;)
strLastName = Request.QueryString(&quot;LastName&quot;)
strEmail = Request.QueryString(&quot;email&quot;)
strLoginName = Request.QueryString(&quot;LoginName&quot;)
strCompanyName = Request.QueryString(&quot;CompanyName&quot;)
strPhoneNumber = Request.QueryString(&quot;PhoneNumber&quot;)
strFaxNumber = Request.QueryString(&quot;FaxNumber&quot;)


strSQLStatement = &quot;Insert into LoginInfo (UserName,PasswordFld,FirstName,LastName,EMailAddress,Status,CompanyName,WorkPhoneNo,FaxNo,UserLevel) &quot; _
+ &quot;values ('&quot; + strUserName + &quot;','&quot; + strPassword + &quot;','&quot; + strFirstName + &quot;','&quot; _
+ strLastName + &quot;','&quot; + strEmail + &quot;','N','&quot; + strCompanyName + &quot;','&quot; _
+ strPhoneNumber + &quot;','&quot; + strFaxNumber + &quot;','NOTUSR')&quot;


set cnIns = Server.CreateObject(&quot;ADODB.Connection&quot;)
cnIns.ConnectionTimeout = 5
cnIns.CommandTimeout = 15

cnIns.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:/xxxDatabase/xxxDatabase.mdb&quot;

Set cmdIns = Server.CreateObject(&quot;ADODB.Command&quot;)
cmdIns.ActiveConnection = cnIns
cmdIns.CommandText = strSQLStatement
cmdIns.CommandType = 1
cmdIns.Execute

cnIns.Close




'Send mail to the administrator.
Dim sendMail
Dim strBody

Set sendMail = CreateObject(&quot;CDONTS.NewMail&quot;)

sendMail.From = strEmail
sendMail.To = &quot;xxx.xxx@xxx.com&quot;
sendMail.bcc = &quot;xxx@xxx.com&quot;

sendMail.Subject = &quot;Request for Login/Password.&quot;

strBody = vbCRLF + vbCRLF + vbCRLF _
& &quot;Request for new Login/Password&quot; _
& vbCRLF + vbCRLF _
& &quot;User Name : &quot; + strUserName + vbCRLF _
& &quot;Password : &quot; + strPassword + vbCRLF _
& &quot;First Name : &quot; + strFirstName + vbCRLF _
& &quot;Last Name : &quot; + strLastName + vbCRLF _
& &quot;Login requested : &quot; + strLoginName + vbCRLF _
& &quot;E mail Address : &quot; + strEmail + vbCRLF _
& &quot;Company : &quot; + strCompanyName + vbCRLF _
& vbCRLF + vbCRLF _
& &quot;Thank You&quot; + vbCRLF _
& strFirstName + &quot; &quot; + strLastName

sendMail.Body = strBody

on error resume next
sendMail.Send


If Err.Number = 0 Then
Else
Response.Write &quot;Error: &quot; & Err.Description
End If



%>

<TABLE WIDTH=&quot;100%&quot;>
<TR>
<TD ALIGN=&quot;CENTER&quot;><BR><BR><BR><BR><STRONG><FONT SIZE=3 COLOR=RED>Your request has been sent.</FONT></STRONG></TD>
</TR>
</TABLE>


</BODY>
</HTML>
 
if you really want to make it generic and straight forward just calling a alert when the var is empty
<%
if UserName = &quot;&quot; then
alert &quot;Please fill in a Name!&quot;
exit sub
else
etc etc...

when you get intot he phone number etc.. check for only number fields nad that it is max length of regular phone number.



email check for the @ . char.
like this
Dim SearchString, SearchChar, MyPos, emal, MyVar 'check for valid email
emal = items.email.value
SearchString = emal
SearchChar = &quot;@&quot;
MyPos = Instr(1, SearchString, &quot;@&quot;)
if MyPos = 0 then

MyVar = MsgBox (&quot;You must fill in a valid E-mail address!&quot;)

elseif MyPos = Instr(1, SearchString, &quot;@&quot;) then
' and so on


here's a script of mine to check for characters in the name etc that only allow letters
Dim bannedchars, charcount, onebanned, valid, inputvalue

bannedchars = &quot;'^\/()#~<>|`¬:;!@$*+=%&quot;
valid = True
inputvalue = form1.Text1.value
inputvalue = Trim(Replace(inputvalue, &quot; &quot;, &quot;&quot;))

For charcount = 1 to Len(bannedchars)
onebanned = Mid(bannedchars, charcount, 1)
If InStr(inputvalue, onebanned) > 0 Then
valid = False
Exit For
End If
Next

If Not valid Then
clientsafeStr = &quot;&quot;
MyVar = MsgBox (&quot;Illegal character entered - Please delete such characters from notes&quot;)
document.Write &quot;<B>Username</B> contains invalid characters.<BR>&quot;
Exit Sub
End If


you can just combine these two scripts fairly easy.

hope that helps out. [bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top