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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validations

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am working on a project and have a HTML page that asks users for userID and password before going to an ASP page. I am trying to figure out how to validate that the ID is numeric and the same password is entered twice.
I was also wondering if the code goes on the ASP page or the HTML page.
If anyone has any ideas, it would be greatly appriciated.
Thanks
 
hi the code will go into the asp page
code
Code:
<%@ Language=VBScript %>
<%Response.Buffer = True%>
<!--#include file=&quot;connect.asp&quot; -->
<%
 dim rs, sql, maker
  maker = &quot;login.asp?rp=&quot; & Request.Form(&quot;goto&quot;) & &quot;&type=1&quot;
  sql = &quot;select * from usermaster where userID = '&quot;& Request.Form(&quot;userid&quot;) &&quot;' and password = '&quot;& Request.Form(&quot;pwd&quot;) &&quot;';&quot;
  set rs = server.CreateObject(&quot;ADODB.RecordSet&quot;)
  rs.Open sql, con, 1, 3
  if rs.EOF = true then 
 'here is where if no username is found then   
 Response.Redirect maker
  else
 'if username is found then
   session(&quot;username&quot;) = Request.Form(&quot;userID&quot;) 
   Response.Redirect &quot;play_match.htm&quot;
  end if 
 rs.Close 
 set rs = nothing
%>
<!--#include file=&quot;close.asp&quot; -->

the connect and close files include the code for connecting to the database Unicorn11
abhishek@tripmedia.com

[red]Life is a stream who's source is hidden[red]
 
Hi Davy770,
Here is simple code:

<html>
<head>
<title>Login</title>
</head>
<BODY>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
function validate()
{
var errormessage='';
for ( var i=1; i <= document.forms[0].ID.value.length;i++)
{
if (isNaN(parseInt(document.forms[0].ID.value.substring(i-1,20))))
errormessage='ID is corrupt!\n'
}
if ((document.forms[0].password1.value) != (document.forms[0].password2.value))
errormessage='Must be same password!\n'
if (errormessage!=&quot;&quot;) alert (errormessage);
else
{
return true;
}
return false;
}
// -->
</SCRIPT>

<form ACTION=&quot;default.asp &quot; METHOD=&quot;post&quot; onSubmit=&quot;return validate();&quot;>
<table border=&quot;0&quot;>
<tr>
<td ALIGN=&quot;right&quot;>ID:</td>
<td><input TYPE=&quot;text&quot; NAME=&quot;ID&quot; size=&quot;20&quot;></td>
</tr>
<tr>
<td ALIGN=&quot;right&quot;>Password:</td>
<td><input TYPE=&quot;password&quot; NAME=&quot;password1&quot; size=&quot;20&quot;></td>
</tr>
<tr>
<tr>
<td ALIGN=&quot;right&quot;>Repeat password:</td>
<td><input TYPE=&quot;password&quot; NAME=&quot;password2&quot; size=&quot;20&quot;></td>
</tr>
<tr>

<td ALIGN=&quot;right&quot;></td>
<td>
<input TYPE=&quot;submit&quot;>
<input TYPE=&quot;reset&quot;> </td>
</tr>
</table>
</form>
</body>
</html>

Best regards,
IR
rizaev@canada.com
 
I agree with IR. The validation should be done on your HTML page form BEFORE it is submitted to your ASP page. That way, the validation is done client side, and should be quicker than submitting the information and then having to deal with invalid information.

Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top