正则表达式简单使用
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script type="text/jscript"> // document.onkeyup = function (event) { function AA(obj) { if (!check(obj.value)) { alert("不正确"); } } //小数点后只能输入3位 function check(c) { var r =/^[+-]?[1-9]?[0-9]*\.?\d{0,3}$/; return r.test(c); } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server" onkeyup="AA(this)"></asp:TextBox> </div> </form> </body> </html>