<%
Rem ==========论坛通用函数=========

Rem Check for valid syntax in an email address.
Function IsValidEmail(email)
	Dim names, name, i, c
	IsValidEmail = True
	names = Split(email, "@")
	If UBound(names) <> 1 Then
	   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))
		 If InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) Then
		   IsValidEmail = False
		   Exit Function
		 End If
	   Next
	   If Left(name, 1) = "." or Right(name, 1) = "." Then
		  IsValidEmail = False
		  Exit Function
	   End If
	Next
	If InStr(names(1), ".") <= 0 Then
	   IsValidEmail = False
	   Exit Function
	End If
	i = Len(names(1)) - InStrRev(names(1), ".")
	If i <> 2 and i <> 3 Then
	   IsValidEmail = False
	   Exit Function
	End If
	If InStr(email, "..") > 0 Then
	   IsValidEmail = False
	End If
End Function

Function StrLength(str)
	ON ERROR RESUME NEXT
	Dim WINNT_CHINESE
	WINNT_CHINESE    = (len("论坛")=2)
	If WINNT_CHINESE Then
		Dim l,t,c
		Dim i
		l=len(str)
		t=l
		For i=1 To l
			c=asc(mid(str,i,1))
			If c<0 Then c=c+65536
			If c>255 Then
				t=t+1
			End If
		Next
		strLength=t
	Else 
		strLength=len(str)
	End If
	If err.number<>0 Then err.clear
End Function

Function CutStr(str,strlen)
	Dim l,t,c
	l=len(str)
	t=0
	For i=1 To l
		c=Abs(Asc(Mid(str,i,1)))
		If c>255 Then
			t=t+2
		Else
			t=t+1
		End If
		If t>=strlen Then
			cutStr=left(str,i)&"..."
			Exit for
		Else
			cutStr=str
		End If
	Next
	CutStr=replace(cutStr,chr(10),"")
End Function

'是否符合只是英文加数字的字串
Function ChkIsEnAndNum(str)
	ChkIsEnAndNum = False
	Dim Re
	Dim IsTrue
	Set re=new RegExp
	Re.IgnoreCase =True
	Re.Global=True
	Re.Pattern="^[a-z0-9]*$"
	IsTrue = Re.test(str)
	If IsTrue = False Then Exit Function
	Re.Pattern="[a-zA-Z]{1,}"
	IsTrue = Re.test(str)
	If IsTrue = False Then Exit Function
	Re.Pattern="[0-9]{1,}"
	IsTrue = Re.test(str)
	If IsTrue = False Then Exit Function
	ChkIsEnAndNum = IsTrue
	Set Re = Nothing
End Function

'是否符合电话规则（手机或电话）
Function ChkIsPhone(str)
	Dim Re
	Set re=new RegExp
	Re.IgnoreCase =True
	Re.Global=True
	Re.Pattern="(^(\d{3,4}-)?\d{7,10})$|([0-9]{9,13})"
	ChkIsPhone = Re.test(str)
	Set Re = Nothing
End Function
%>
