+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Search Box

Search Box

4 posts, 0 answered
  1. Smitha
    Smitha avatar
    22 posts
    Registered:
    29 Oct 2008
    29 Dec 2008
    Link to this post
    Hi!

    1) Is there a way to limit the charecters entered in a search box?

    2) Can we restrict the serach box to only take charecters and not special charecters. If we enter <B> then the serach page displays error.

    Regards,
    Smitha.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    29 Dec 2008
    Link to this post
    Hi Smitha,

    Thank you for using our services.

    1. You can add new regular expression pattern in your web.config file as below:

     <searchInputValidation> 
            <add matchPattern="\A[\*\?\~][^\s]*" replacementString="" enabled="true" matchAlert="You can not start your query using wildcards, modify your query and try again.." /> 
            <add matchPattern="[\!\^\(\)\{\}\[\]]" replacementString="" enabled="true" matchAlert="Strange characters should be enclosed between double quotation, modify your query and try again.." /> 
            <add matchPattern="[a-zA-Z0-9\r\n]{1,3}" replacementString="" enabled="true" matchAlert="cannot use more that 3 symbols"/> 
          </searchInputValidation> 

    Then, open SearchResults control in edit mode and set EscapeSpecialChars property to false.

    2. You can add RegularExpressionValidator control in the SearchBox template under ~/Sitefinity/ControlTemplates/Search/SearchBox.ascx

    <fieldset class="sf_searchBox"
        <asp:Label runat="server" AssociatedControlID="queryText" Text="Search" /> 
        <asp:TextBox ID="queryText" runat="server" CssClass="sf_searchText"></asp:TextBox> 
        <input type ="button" id="searchButton" runat="server" class="sf_searchSubmit" value="Search" alt="Search"/> 
     
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1"    
    runat="server" ControlToValidate="queryText" ErrorMessage="you cannot use more than 3 symbols"   
    ValidationExpression="[a-zA-Z0-9\r\n]{1,3}"></asp:RegularExpressionValidator>  
    </fieldset> 
     
     

    The examples above restrict using of more than 3 symbols when searching. Using regular expression you can limit the symbols that can be used.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Rama Krishna
    Rama Krishna avatar
    14 posts
    Registered:
    20 Nov 2008
    05 Jan 2009
    Link to this post
    Hi ,

    Can we limit search box  to search with html tags like '<a>' using regular expression?  It's blowing with following error when I was search the site with <a> word.

    "'A potentially dangerous Request.QueryString value was detected from the client (SearchQuery="<a>")' .

    I tried with different regular expressions but unable to suceeded.  Please guide me if you have any solution.

    Thanks,
           RK


  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    08 Jan 2009
    Link to this post
    Hello Rama,

    This a standard ASP.NET behavior.
    There is a way to prevent getting this error message, but it is a potential risk for your website to have this working.
    For more information check out validateRequest and enableEventValidation.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Register for webinar
4 posts, 0 answered