[英]check if a hiddenfield contains more text other than commas with regular expression
我需要創建一個asp.net驗證程序控件,該控件僅在hiddenfield不為空且不只包含逗號的情況下才允許發布頁面。
<asp:HiddenField ID="hdnProductListTip" ClientIDMode="Static" runat="server" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="You must have at least one product selected against your tip" ControlToValidate="hdnProductListTip"></asp:RegularExpressionValidator>
我需要在驗證器中使用什么表達式?
我認為,您不能通過正則表達式使用它。 對Button ClientClick事件使用Javascript。
<script language="javascript" type="text/javascript">
function CheckHiddenField() {
debugger;
var ID = document.getElementById('<%=HiddenField1.ClientID %>');
Trim(ID);
if (ID.value == '')
return false;
if (ID.value.indexOf(',') > 0) {
return false;
}
return true;
}
function Trim(ID) {
LeftTrim(ID);
RightTrim(ID);
}
function LeftTrim(Obj) {
var Trim = new RegExp('^\\s*');
Obj.value = Obj.value.replace(Trim, '');
}
function RightTrim(obj) {
var Trim = new RegExp('\\s*$');
obj.value = obj.value.replace(Trim, '');
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.