一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

asp 用户登录代码

时间:2010-10-13 编辑:简简单单 来源:一聚教程网

文章提供一款简单的asp 用户登录代码,提供了从数据库教程连接到文件的登录以及用户在输入信息时js判断验证哈。
<%
'dim databasename,conn,constr
databasename="userman.mdb"
constr="provider=microsoft.jet.oledb.4.0;data source=" & server.mappath(databasename)
set conn=server.createobject("adodb.connection")
conn.open constr
%>

登录页面文件


请输入用户名和密码

用户注册







 
   
   
 
 
   
   
 
  
   
   
 

 

用 户 名: *用户名只能输入大写或小写字母
密  码: *密码只能输入数字
电子邮件: *请填写正确的邮件格式

  





登录处理文件
<%
'读取从表单传递过来的身份数据
username=trim(request.form("username"))
userpwd=request.form("userpwd")
email=request.form("email")

if username="" or userpwd="" or email="" then
 response.write ""
 response.end
elseif not checkletter(username) then
 response.write ""
 response.end
elseif not isnumeric(userpwd) then
 response.write ""
 response.end
elseif not isvalidemail(email) then
 response.write ""
 response.end
elseif len(username)<6 then
 response.write ""
 response.end
else
 response.write "

输入正确!"
end if

function checkletter(str)
 checkletter=true
 letters="abcdefghijklmnopqrstuvwxyz"
 for i=1 to len(str)
  checkchar=ucase(mid(str,i,1))   返回字符串str中第i个字符,并将其转换为大写
  if (instr(letters,checkchar)<=0) then   'checkchar对应字符在letters中不存在
   checkletter=false
   exit function
  end if
 next
end function

function isvalidemail(email)
 dim names,name,i,c
 isvalidemail=true
 names=split(email,"@")   '使用@字符将email字符串分成几个子字符串并保存在names数组中
 if ubound(names)<>1 then
  'ubound函数返回数组names的最大下标,ubound(names)<>1表明email字符串中存在@字符且不只一个,所以email不是有效的邮件地址格式
  isvalidemail=false
  exit function
 end if
 for each name in names
  if len(name)<=0 then
   isvalidemail=false
   exit function
  end if
  for i=1 to len(name)
   c=lcase(mid(name,i,1))
   '返回字符串name内第i个字符并将其转换成小写
   if instr("abcdefghijklmnopqrstuvwxyz_-.",c)<=0 and not isnumeric(c) then
    'instr函数返回指定字符串在另一字符串中第一次出现的位置。instr("abcdefghijklmnopqrstuvwxyz_-.",c)<=0表明字符c不在字符串"abcdefghijklmnopqrstuvwxyz_-."中
    isvalidemail=false
    exit function
   end if
  next
  if left(name,1)="." or right(name,1)="." then
   '返回字符串name最左边一个字符,返回字符串name最右边一个字符
   isvalidemail=false
   exit function
  end if
 next
 if instr(names(1),".")<=0 then
  'email字符串中@右边部分不包含字符”.”
  isvalidemail=false
  exit function
 end if
 i=len(names(1))-instrrev(names(1),".")
 'instrrev函数返回指定字符串在另一个字符串中出现的从结尾计起的的位置,instrrev(names(1),".")得到字符"."在字符串names(1) 中从结尾计起的位置
 if i<>2 and i<>3 then
  '电子邮件最后一般为cn或com,长度为2或3
  isvalidemail=false
  exit function
 end if
 'email中存在字符串".."
 if instr(email,"..")>0 then
  isvalidemail=false
 end if
end function
%>

热门栏目