自定義的驗證無法正常工作,請檢查javascript和下面的代碼自定義的驗證是不是在我的形式工作
<script type="text/javascript">
function checkalphabets(sender, args) {
var pattern = /^[a-zA-Z\s]+$/;
var regexp1 = new RegExp("(www|http|https|WWW|HTTP|HTTPS)");
var sUser = <%= CreateFirstNameTextBox.ClientID %>.value;
if ((!pattern.test(args.value))|| (regexp1.test(args.value)))
{
return false;
}
return true;
}
</script>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" ID="CreateFirstNameTextBox" placeholder="First Name"
MaxLength="50"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator2" runat="server" ErrorMessage="Only Alphabets allowed! & http, www, https are not allowed"
ClientValidationFunction="checkalphabets" ForeColor="red" ControlToValidate="CreateFirstNameTextBox"
ValidationGroup="create" />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" ValidationGroup="create" />
</div>
</form>
我必須只允許字母到文本框,不應該讓WWW,HTTP, HTTPS
可以告訴你的渲染代碼,而隨後的模板。可能會更容易知道正在運行的實際代碼 – atmd
是否在控制檯中看到任何錯誤? – Grundy
它不工作@Grundy –