JS验证Email 及 数字

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JAlert_2.aspx.cs" Inherits="JQueryStudy.JAlert_2" %>

<!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">
    <title></title>     
    <script type="text/javascript" defer="defer">      

        function isEmail(strEmail)
        {
            if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
                return true;
            else
                alert("您输入的Email不合法,请重新输入!");
        }
      
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:TextBox ID="TextBox1" runat="server" onblur="javascript:return isEmail($(this).val());"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click"  />
    </div>
    </form>
</body>
</html>

 

验证文本框中只能输入数字,如果不是数字,自动去掉

<asp:TextBox ID="txtTraineeNo" runat="server"  onkeyup="value=value.replace(/[^\d]/g,'')"></asp:TextBox>

上面可以,下面不可以

function isNum(s)
{
    return s.replace(/[^\d]/g, '');
}

<asp:TextBox ID="txtTraineeNo" runat="server"  onkeyup="value=isNum($(this).val()) >asp:TextBox>

 

你可能感兴趣的:(email)