.NET客户端的数据验证实例

Aapx代码块
<form id="form1" runat="server">
    
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    
<asp:Button ID="Button7" runat="server" OnClick="Button7_Click" OnClientClick="javascript:return checkForm()"  Text="提交" />
</form>

JavaScript代码块
<script language="javascript" type="text/javascript">

        function checkForm() 
{
            
if (document.form1.TextBox1.value == ""{
                alert(
"怎么是空的!");
                document.form1.TextBox1.focus();
                
return false;
            }

            var length 
= document.form1.TextBox1.value.length;
            
if (length < 6 || length > 10{
                alert(
"必须是6~10个字符内!");
                
return false;
            }

        }

    
    
</script>
posted @ 2009-09-16 14:59  王翔(kingfly)  阅读(349)  评论(1编辑  收藏  举报