求一个验证函数,只允许数字(0~9)和字符(A~Z)的组合!

ghost225 2005-12-25 09:39:39
如题!
...全文
1464 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
KiteGirl 2005-12-28
  • 打赏
  • 举报
回复
Private priTable() As Byte

Private Sub Form_Load()
ReDim priTable(0 To 255)
TableFillByString priTable(), "0", "9"
TableFillByString priTable(), "A", "Z"
End Sub

Private Sub Command1_Click()
Dim tString As String
tString = Text1.Text
If Not tString = "" Then
Dim tBytes() As Byte
tBytes() = StrConv(tString, vbFromUnicode)
Text2.Text = BytesCheck(tBytes(), priTable())
End If
End Sub

Function BytesCheck(ByRef pBytes() As Byte, ByRef pTable() As Byte) As Boolean
Dim tOutBool As Boolean

Dim tBytes_Start As Long
Dim tBytes_End As Long

tBytes_Start = LBound(pBytes())
tBytes_End = UBound(pBytes())

Dim tBytes_Index As Long

tOutBool = True

For tBytes_Index = tBytes_Start To tBytes_End
tOutBool = tOutBool And CBool(pTable(pBytes(tBytes_Index)))
If Not tOutBool Then Exit For
Next

BytesCheck = tOutBool
End Function

Sub TableFillByString(ByRef pBytes() As Byte, ByVal pStartStr As String, ByVal pEndStr As String)
Dim tStart As Integer
Dim tEnd As Integer

tStart = AscW(pStartStr)
tEnd = AscW(pEndStr)

TableFillByValue pBytes, tStart, tEnd
End Sub

Sub TableFillByValue(ByRef pBytes() As Byte, ByVal pStart As Integer, ByVal pEnd As Integer)
Dim tIndex As Long

For tIndex = pStart To pEnd
pBytes(tIndex) = &HFF
Next
End Sub
KiteGirl 2005-12-28
  • 打赏
  • 举报
回复
我有个新算法,少等!
northwolves 2005-12-28
  • 打赏
  • 举报
回复
To samwzhang(分全给我)

northwolves(狼行天下) 的这个方法是对的,但是写错了具体的命令:
Function HEFA(ByVal x As String) As Boolean
HEFA = Not x Like "*[!A-Z,0-9]*"
End Function
______________
应该是:

Function HEFA(ByVal x As String) As Boolean
HEFA = x Like "*[!A-Z,a-z,0-9]*"
End Function
------------------------

楼主要求只允许数字(0~9)和字符(A~Z)的组合,即
123 True
ABC True
ABC123# False
abc False

你的代码意思是只有当字符串包含(非数字和大小写字母的字符)时才合法,不信试试
思诺赛克 2005-12-26
  • 打赏
  • 举报
回复
学习
junki 2005-12-26
  • 打赏
  • 举报
回复
或者根据ASCII值来判断
coyihisaso 2005-12-26
  • 打赏
  • 举报
回复
真是你方唱罢我登场,都很好啊,除了遥控器广告~-~
老狼语句精妙。学习中...
HungryBoy 2005-12-26
  • 打赏
  • 举报
回复
把小写的转换成大写的就可以了
'*************************************************************************
'**模 块 名:GetRndChr
'**输 入:iLen
'**输 出:GetRndChr
'**说 明:
'**创 建 人:
'**日 期:2005-12-5
'**修 改 人:
'**日 期:
'**描 述:随机生成iLen长的由数字小写字母组成的字符串
'**版 本:
'*************************************************************************
Public Function GetRndChr(iLen As Integer) As String
Dim str_id As String
Dim str As String
Dim rnd0 As Integer
Randomize
Do While Len(str_id) <= iLen
rnd0 = Int((3 - 1 + 1) * Rnd + 1)
Select Case rnd0
Case 1
rnd0 = Int((57 - 48 + 1) * Rnd + 48)
Case 2
rnd0 = Int((90 - 65 + 1) * Rnd + 65)
Case 3
rnd0 = Int((122 - 97 + 1) * Rnd + 97)
End Select
str = Chr(rnd0)
str_id = str_id + str
Loop
GetRndChr = LCase(str_id)
End Function
gsec01001 2005-12-26
  • 打赏
  • 举报
回复
案之“如何避免因为看电视而和老婆吵架”




1、 在老婆面前彻底放弃这个公民的基本权利。
2、 不怕流血,坚持斗争。
3、 实现民主,平均分配时间,如1、3、5和2、4、6分开。
4、 再买另一台电视,但恐怕当她在看电视的时候如果没有你做听众,结果还是一样。出于响应国家节约

型社会的号召,此方法不作为重点推荐。
5、 网上订阅一份“阳光 电视 导航 <http://www.gogosun.com/>”提前做好选择,如果太多的话
分出重点,逐个击破。然后提前给老婆做工作,并付出一些补偿(money)。记住语气要温柔,态度要诚恳。争

取达到目的,不行的话采取重点突破。此方法行之有效。不防尝试。
云网LOGO地址:http://www.cncard.com/images/cncard_logo1.gif
云网链接地址:http://www.cncard.com/products/566.shtml
阳光 电视 导航LOGO地址:http://www.gogosun.com/new2005/images/logo.gif
阳光 电视 导航链接地址:http://www.gogosun.com



gsec01001 2005-12-26
  • 打赏
  • 举报
回复
摇控器的抱怨



电视机大哥,能否给主人放个好节目,主人回家就拿我当手指按摩器,乱按一通,还JJWW的,动不动让我在茶

几上空做空翻。 电视机:遥控器老弟,我看你也近朱者赤,近墨者黑,最近也对我这么JJWW的,SJB赶快告诉

老大订购阳光 电视 导航吧,免得咱们都受罪,我还不是眨的眼睛疼。 ]
快快下载国内首款电视多媒体杂志,杨澜制造,免费赠阅!
http://www.gogosun.com/new2005/gonggao.html
这是公司的网址:http://www.gogosun.com
云网LOGO地址:http://www.cncard.com/images/cncard_logo1.gif
云网链接地址:http://www.cncard.com/products/566.shtml
阳光 电视 导航LOGO地址:http://www.gogosun.com/new2005/images/logo.gif
阳光 电视 导航链接地址:http://www.gogosun.com

51365133 2005-12-26
  • 打赏
  • 举报
回复
northwolves(狼行天下)的不错,高人。
zou19820704 2005-12-26
  • 打赏
  • 举报
回复
function X (str as string) as boolean
for i = 1 to len(str)
if (asc(mid(str,i,1))< asc("Z") and asc(mid(str,i,1)))> asc("A") or (asc(mid(str,i,1))< asc("9") and asc(mid(str,i,1))>asc("0")) then
x= true
else
x=false
exit function
end if
next
end function
ASCII码判定,容易理解的代码!
samwzhang 2005-12-26
  • 打赏
  • 举报
回复
northwolves(狼行天下) 的这个方法是对的,但是写错了具体的命令:
Function HEFA(ByVal x As String) As Boolean
HEFA = Not x Like "*[!A-Z,0-9]*"
End Function
______________
应该是:

Function HEFA(ByVal x As String) As Boolean
HEFA = x Like "*[!A-Z,a-z,0-9]*"
End Function


xooe 2005-12-26
  • 打赏
  • 举报
回复
zou19820704(国际海员)的不错,重点推荐!
代码是多了几行,执行效率较高。
wxrwan 2005-12-25
  • 打赏
  • 举报
回复
学习!
northwolves 2005-12-25
  • 打赏
  • 举报
回复
更简单的:

Function HEFA(ByVal x As String) As Boolean
HEFA = Not x Like "*[!A-Z,0-9]*"
End Function
northwolves 2005-12-25
  • 打赏
  • 举报
回复
Function HEFA(ByVal x As String) As Boolean
HEFA = True
Dim I As Integer
For I = 1 To Len(x)
If Not (Mid(x, I, 1) Like "[A-Z]" Or Mid(x, I, 1) Like "#") Then
HEFA = False
Exit For
End If
Next
End Function
ghost225 2005-12-25
  • 打赏
  • 举报
回复
自己顶一下先!

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧