繁体   English   中英

检查隐藏字段是否包含除带正则表达式的逗号以外的更多文本

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM