'**********判断text中是否为空,或者判断其中是否允许输入数字或字符
Public Function bTxtFmat(ByVal strTxt As String, ByVal iTxtType As Integer, ByVal bNullAllow As Boolean, ByVal strCaption As String) As Boolean
'txt=text.text
'txttype=1,2,3(1=数字型,2=字符型,3=汉字,4=数字和字符)
'nullallow=是否允许为空,true=可以为空。
'caption=显示文本框内容的标题
Dim i, k, m As Integer
If bNullAllow = False Then
If Len(strTxt) = 0 Then
MsgBox("" & strCaption & "输入项中内容不允许为空,请重新输入!", MsgBoxStyle.Exclamation, "系统警告")
bTxtFmat = False
Exit Function
End If
End If
k = Len(strTxt)
Select Case iTxtType
Case 1
For i = 1 To k
m = Asc(Right(Left(strTxt, i), 1))
If m < 48 Or m > 57 Then
MsgBox("" & strCaption & "输入项中只允许输入数字", MsgBoxStyle.Exclamation, "系统警告")
bTxtFmat = False
Exit Function
End If
Next
Case 2
For i = 1 To k
m = Asc(Right(Left(strTxt, i), 1))
If m < 65 Or (m > 91 And m < 97) Or m > 123 Then
MsgBox("" & strCaption & "输入项中只允许输入字符", MsgBoxStyle.Exclamation, "系统警告")
bTxtFmat = False
Exit Function
End If
Next
Case 3
For i = 1 To k
m = Asc(Right(Left(strTxt, i), 1))
If m >= 0 Then '汉字首位为1,按有符号计算全部为负数
MsgBox("" & strCaption & "输入项中只允许输入汉字!", MsgBoxStyle.Exclamation, "系统警告")
bTxtFmat = False
Exit Function
End If
Next
Case 4
For i = 1 To k
m = Asc(Right(Left(strTxt, i), 1))
If m < 0 Then '汉字首位为1,按有符号计算全部为负数
MsgBox("" & strCaption & "输入项中不允许输入汉字!", MsgBoxStyle.Exclamation, "系统警告")
bTxtFmat = False
Exit Function
End If
Next
End Select
bTxtFmat = True
End Function
Public Function bTxtFmat(ByVal strTxt As String, ByVal iTxtType As Integer, ByVal bNullAllow As Boolean, ByVal strCaption As String) As Boolean
'txt=text.text
'txttype=1,2,3(1=数字型,2=字符型,3=汉字,4=数字和字符)
'nullallow=是否允许为空,true=可以为空。
'caption=显示文本框内容的标题
Dim i, k, m As Integer
If bNullAllow = False Then
If Len(strTxt) = 0 Then
MsgBox("" & strCaption & "输入项中内容不允许为空,请重新输入!", MsgBoxStyle.Exclamation, "系统警告")
bTxtFmat = False
Exit Function
End If
End If
k = Len(strTxt)
Select Case iTxtType
Case 1
For i = 1 To k
m = Asc(Right(Left(strTxt, i), 1))
If m < 48 Or m > 57 Then
MsgBox("" & strCaption & "输入项中只允许输入数字", MsgBoxStyle.Exclamation, "系统警告")
bTxtFmat = False
Exit Function
End If
Next
Case 2
For i = 1 To k
m = Asc(Right(Left(strTxt, i), 1))
If m < 65 Or (m > 91 And m < 97) Or m > 123 Then
MsgBox("" & strCaption & "输入项中只允许输入字符", MsgBoxStyle.Exclamation, "系统警告")
bTxtFmat = False
Exit Function
End If
Next
Case 3
For i = 1 To k
m = Asc(Right(Left(strTxt, i), 1))
If m >= 0 Then '汉字首位为1,按有符号计算全部为负数
MsgBox("" & strCaption & "输入项中只允许输入汉字!", MsgBoxStyle.Exclamation, "系统警告")
bTxtFmat = False
Exit Function
End If
Next
Case 4
For i = 1 To k
m = Asc(Right(Left(strTxt, i), 1))
If m < 0 Then '汉字首位为1,按有符号计算全部为负数
MsgBox("" & strCaption & "输入项中不允许输入汉字!", MsgBoxStyle.Exclamation, "系统警告")
bTxtFmat = False
Exit Function
End If
Next
End Select
bTxtFmat = True
End Function
解决方案 »
- 第一次用.net程序,小白请教个问题
- 未能加载文件或程序集"Interop.SWFToImage"或它的一个依赖
- 在GridView的FooterRow中如何使用onclick事件?
- 我的gridview控件的数据源指定了一个accessdatasource,但是点击gridview右上角的三角之后,弹出的菜单里面没有“启用编辑”这一项,为什么?
- 模态窗口刷新
- 我想在DATALIST中动态增加一个超级链接应怎么样做呢?
- ASP.NET发布问题,求高手求解
- <identity impersonate="true" userName="domain\account" password="password"/>
- 非静态的字段、方法或属性“System.Web.UI.WebControls.FileUpload.HasFile.get”要求对象引用
- =====打印table中的内容=====
- 网页的显示问题!
- 如何将日期类型的2004-9-8转换成整数型的20040908呢?
正则表达式如下:
\d+\.?\d*|\.\d:不能为负
-{0,1}(\d+|\d+\.\d+)$:可以为负
用正则表达式限制用户输入汉字:using System.Text.RegularExpressions; ......string str;......bool yn=Regex.IsMatch(str,@"^[\u4e00-\u9fa5]+$");
if(yn==true)
{
MessageBox.Show("y"); //汉字
}
else
{
MessageBox.Show("n"); //不是汉字
}