找回密码
 加入
搜索
查看: 1496|回复: 4

如何判断字符串仅含有字母和数字?StringIsAlNum 这个函数没有用!

[复制链接]
发表于 2008-10-25 23:22:59 | 显示全部楼层 |阅读模式
[au3]$a = "This is a sentence with whitespace."
MsgBox(0,"StringIsAlNum returns:", StringIsAlNum($a))

$b = "This is 123"
MsgBox(0,"StringIsAlNum returns:", StringIsAlNum($b))

$c = "This is 他们"
MsgBox(0,"StringIsAlNum returns:", StringIsAlNum($c))

$d = "12356"
MsgBox(0,"StringIsAlNum returns:", StringIsAlNum($d))[/au3]

前三行返回都是0,等同于 StringIsAlpha 函数;第四行返回1,等同于 StringIsDigit 函数!

[ 本帖最后由 陌上风 于 2008-10-26 09:22 编辑 ]
发表于 2008-10-26 08:37:08 | 显示全部楼层
$a = "This123"
if StringRegExp($a,"^(\d|\w)+$",0) Then
        MsgBox(0,'info','该字符串只包含字母和数字.')
EndIf
 楼主| 发表于 2008-10-26 09:22:56 | 显示全部楼层
谢谢,还是正则表达式厉害,可惜我还没学会
发表于 2009-6-22 14:10:30 | 显示全部楼层
^(\d|\w)+$ 是什么意思呢?
发表于 2009-6-22 16:18:46 | 显示全部楼层
\d Match any digit (0-9).
\w Match any "word" character: a-z, A-Z, 0-9 or underscore (_).
\d 匹配任意数字字符,从0-9
\w 匹配任意单词字符,从a到z,从A到Z,从0到9,以及_字符
匹配方法:
1.StringRegExp($s_String, "\A[\da-zA-Z]+\Z"), 返回1, 表示仅仅包含a-z,A-Z,0-9的字符
\A,\Z 分别代表字符串的开头与结尾(不表示任何字符,仅表示位置关系).
+ 表示至少拥有一个字符
2.StringRegExp($s_String, "(?i)\A[\da-z]+\Z"),与上同.
不同之处在于,使用了(?i)来使大小写不敏感.
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-10 17:40 , Processed in 0.073170 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表