开发者

Issues with RegularExpressionValidator in VB .NET 2005 using ASP File Uploader

I'm looking to validate a single word: detail (upper/lower/mix-case) prior to submitting my VB .NET 2005 page. I used Regex Builder and the below code validates, but it's not working in my web page... Does anyone have any ideas?

        Input file location:
    <input id="btnBrowseForFile" runat="server" enableviewstate="true" name="btnBrowseForFile"
        style="width: 500px" type="file" />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2"
            runat="server" ControlToValidate="btnBrowseForFile" ErrorMessage="*Please select an input file." Display="Dynamic"></asp:RequiredFieldValidator>
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="btnBrowseForFile"
        Display="Dynamic" ErrorMessage='*Please select a file that conta开发者_JAVA百科ins the word "detail"'
        ValidationExpression="(\b|\s|\w)(d|D)(e|E)(t|T)(a|A)(i|I)(l|L)(\s|\b|\w)"></asp:RegularExpressionValidator>&nbsp;

Thanks!!! JFV


If you simply want to check for word detail in a string try this:

ValidationExpression="^.*(d|D)(e|E)(t|T)(a|A)(i|I)(l|L).*$"


i am not sure if the regularexpressionvalidator allows a regular html control in its controltovalidate attribute. try using the asp:FileUpload Control as follows:

<asp:FileUpload id="fileUpload" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
    runat="server"
    ControlToValidate="fileUpload"
    ErrorMessage="*Please select an input file."
    Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
    ID="regexFileUpload"
    runat="server"
    ControlToValidate="fileUpload"
    Text="Only Files with the word detail allowed"
    Display="Dynamic"
    ValidationExpression="(\b|\s|\w)(d|D)(e|E)(t|T)(a|A)(i|I)(l|L)(\s|\b|\w)" />

haven't tested this but this should work.


Haven't been doing asp.net for some time now, my first reflex would be to check out the validation javascript that is output and make sure it is ok in regards to your input.

I would also try using the asp:FileUpload server control to see if it works (maybe the HtmlControl has not a correct ClientID sent in to the validation script. Here is a link showing how to use it. You would just need to change your input for the FileUpload control in regard to validation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜