CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
英特尔®游戏设计大赛100美元现金周周送 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  ASP.NET

如何判斷文本框中輸入是否是數字?

楼主icefirelxb(icefire)2003-11-01 14:52:39 在 .NET技术 / ASP.NET 提问

如何判斷文本框中輸入是否是number? 问题点数:0、回复次数:7Top

1 楼icefirelxb(icefire)回复于 2003-11-01 15:12:54 得分 0

比如說number(6,4)Top

2 楼wwonion(洋葱)回复于 2003-11-01 15:33:49 得分 0

用  
  egularExpressionValidator  
  <asp:TextBox   id="TextBox1"   runat="server"></asp:TextBox>  
  <asp:RegularExpressionValidator   id="RegularExpressionValidator1"   runat="server"   ErrorMessage="你只能输入数字"   ControlToValidate="TextBox1"   ValidationExpression="^[0-9]+$"></asp:RegularExpressionValidator>Top

3 楼icefirelxb(icefire)回复于 2003-11-01 15:48:39 得分 0

注意,裡面有小數點Top

4 楼xvting(xvting)回复于 2003-11-01 16:32:55 得分 0

学习Top

5 楼icefirelxb(icefire)回复于 2003-11-01 16:56:53 得分 0

哪位大人榜幫忙Top

6 楼icefirelxb(icefire)回复于 2003-11-01 17:46:09 得分 0

用RegularExpressionValidator1系統提示沒有安裝,還是什麼意思。怎麼辦?我想自己寫函數?但是怎麼把字符串的字符一個個讀出來?Top

7 楼Dugu_Niu(Zealot.name)回复于 2003-11-01 18:27:31 得分 0

最好做一个用户控件,以便以后重复使用,  
  从TextBox继承  
  在KeyPress事件中写以下代码:  
  Dim   KeyAscii   As   Integer  
                  KeyAscii   =   Asc(e.KeyChar)  
   
                  Select   Case   KeyAscii  
   
                          Case   48   To   57,   8,   13             '   these   are   the   digits   0-9,   backspace,    
                                  '   and   carriage   return  
                                  '   we're   OK   on   these,   don't   do   anything  
   
                          Case   45                                       '   minus   sign  
   
                                  '   if   we   already   have   one,   throw   it   away  
                                  If   InStr(Me.Text,   "-")   <>   0   Then  
                                          KeyAscii   =   0  
                                          Exit   Sub  
                                  End   If  
   
                                  '   if   the   insertion   point   is   not   sitting   at   zero  
                                  '   (which   is   beginning   of   field),   throw   away   the   minus  
                                  '   sign   (because   it's   not   valid   except   in   first   position)  
                                  If   Me.SelectionStart   <>   0   Then  
                                          KeyAscii   =   0  
                                  End   If  
   
                          Case   46                                       '   this   is   a   period   (decimal   point)  
   
                                  '   if   we   already   have   a   period,   throw   it   away  
                                  If   InStr(Me.Text,   ".")   <>   0   Then  
                                          KeyAscii   =   0  
                                  End   If  
   
                          Case   Else  
                                  '   provide   no   handling   for   the   other   keys  
                                  KeyAscii   =   0  
   
                  End   Select  
   
                  '   If   we   want   to   throw   the   keystroke   away,   then   set   the   event  
                  '   as   already   handled.   Otherwise,   let   the   keystroke   be   handled   normally.  
                  If   KeyAscii   =   0   Then  
                          e.Handled   =   True  
                  Else  
                          e.Handled   =   False  
                  End   If  
  做好之后编译生成dll文件,然后在你的项目中引用这个dll就可以  
  Top

相关问题

  • 判断文本框内容是否是字符串
  • 页脚的文本框判断是否是数字
  • 谁写一段js来判断文本框中输入是否特殊字符。
  • 请问文本框的TextChanged事件判断输入的字符是否规范?
  • 在JAVASCRIPT 中,如何判断文本框中是否包涵“全类”二字,是否含有汉字???
  • 判断文本框
  • 如何判断访问者在文本框中输入的是否数字(比如信用卡号)(ASP.NET,C#)?
  • 用VBA判断word文档中的文本框内是否存在文字?????(急急急!! )
  • 判断提交表单中的文本框的值是否和数据库中的字段重复
  • 怎样判断一个文本框里是否有另一个文本框的内容?

关键词

  • me
  • keyascii
  • away
  • already
  • handled
  • throw
  • case
  • then

得分解答快速导航

  • 帖主:icefirelxb

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo