- <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
- <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
- YzTest
- </asp:Content>
- <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
- <script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
- <script type="text/javascript">
- $(document).ready(function () {
- $("#Form1").submit(function () {
- var a = $("#Email").val();
- var validate = true;
- alert(a);
- if (a == "") {
- validate = false;
- $("#DEmail").html("对不起,该选项不能为空");
- }
- else {
- var reg =/^(0|[1-9]\d*)$/;
- alert(reg.test(a));
- if (reg.test(a)) {
- if (a > 100 || a < 0) {
- alert("a");
- validate = false;
- $("#DEmail").html("年龄范围在0-100之间!");
- }
- else {
- $("#DEmail").html("");
- }
- }
- else {
- $("#DEmail").html("请输入数字");
- validate = false;
- }
- }
- return validate;
- });
- });
- </script>
- <h3>验证测试</h3>
- <%using (Html.BeginForm("YzTest", "Home", FormMethod.Post, new { id = "Form1" }))
- {%>
- <table>
- <tr>
- <td>
- (Email验证)
- </td>
- <td><input type="text" id="Email"/><div id="DEmail"></div></td>
- </tr>
- <tr><td><input type="submit" value="验证" /></td></tr>
- </table>
- <%} %>
- </asp:Content>
贴代码。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。