checkusername.txt

来自「ajax技术书籍 ajax技术书籍」· 文本 代码 · 共 57 行

TXT
57
字号
Name: 用户名检查函数
Author: shemily
Create: 2007-04-29
Version: 1.0
Language: VBscript

<%
'------------参数说明-------------
'checkName	--需要检查的用户名
'table		--用户名所保存的表名
'fieldName	--用户名的字段名
'---------------------------------
function checkUserName(checkName, table, fieldName)
	Response.Expires = -1
	Response.ExpiresAbsolute = Now() - 1
	Response.cachecontrol = "no-cache"
	
	dim backStr,con,rs
	
	if(checkName="") then						'if userName is null
		backStr = "Err_101"
	else
		'wrong username check
		Set re = New RegExp
		re.Pattern = "^\d{1}.*"
		if(re.Test(checkName)) then				'if userName start with a number
			backStr = "Err_103"
		else
			re.Pattern = "[\- \+ \\ \/ \& ! ~ @ # \$ % \^ \* \( \) = \? '  \< \> \. , : ; \] \[ \{ \} \|]"
			if(re.Test(checkName)) then			'if userName include some no letter
				backStr = "Err_104"
			else
				set con=getConn()
				set rs=getRs()
				sql="select top 1 * from "&table&" where "&fieldName&"='"&checkName&"'"
				rs.open sql,con,1,1
	
				if not rs.bof and not rs.eof then	'if userName is not exists
					backStr = "Err_100"
				else					'if userName is exists
					backStr = "Err_102"
				end if
	
				rs.close
				con.close
				set rs=nothing
				set con=nothing
			end if
		
		end if
	
	end if
	
	checkUserName = backStr		'return error code
	
end function
%>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?