问题描述
VB.NETWEB页面中,有一个Textbox框,我让用户输入的是2008/12/06类似的日期,如何判断用户输入的正确性!如果不正确,则给出一个提示,并让光标仍然停留在textbox中并全选.请问如何做呢?谢谢!
解决方案
解决方案二:
你这样很难验证,情况太多了,为何不用时间控件呢。AjaxToolkit中的Canlender控件,可以设定时间格式,不用自己验证了,而且很容易设置。
解决方案三:
用CompareValidator验证控件!!
解决方案四:
验证控件方便些
解决方案五:
这是一个例子:<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>无标题页</title></head><body><formid="form1"runat="server"><asp:TextBoxID="TextBox1"runat="server"ontextchanged="TextBox1_TextChanged"></asp:TextBox><asp:ButtonID="Button1"runat="server"Text="Button"/></form></body></html>
usingSystem;publicpartialclass_Default:System.Web.UI.Page{protectedvoidTextBox1_TextChanged(objectsender,EventArgse){try{DateTimedt=DateTime.Parse(TextBox1.Text);}catch(Exceptionex){Page.ClientScript.RegisterStartupScript(this.GetType(),"error","alert('"+ex.Message.Replace("'","\'").Replace("rn","n")+"');",true);this.TextBox1.Focus();}}}
当你使用UpdataPanel时,基本上无需修改代码(可以考虑将Page.ClientScript换成ScriptMamager)。
解决方案六:
有没有VB.NET版本的?
解决方案七:
用验证控件喽。JS也可以!验证控件分VB,C#?
解决方案八:
TO:sp1234可以用VB.NET吗?