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

Forums / Bugs & Issues / Search box validations

Search box validations

4 posts, 0 answered
  1. shraddha
    shraddha avatar
    87 posts
    Registered:
    18 May 2009
    17 Jun 2009
    Link to this post

    Hi,

    I am using search input validations for search box.
    There are 2 default patterns in web.config for validations which i can't remove.

    <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.." />

    What if I want to use validation only for minimum and maximum characters and i want to allow all the characters.

     

  2. Parvan
    Parvan avatar
    151 posts
    Registered:
    24 Sep 2012
    19 Jun 2009
    Link to this post
    Hello Shraddha,

    The input validations are regular expressions which are executed on server after the search button is pressed. In order to enable search input validation you must set the EscapeSpecialChars property of the SearchResult control to false (from the Advanced Edit tab). You can set EscapeSpecialChars to true and they will not be checked (or directly delete the two rules from the web.config file).

    If you want to validate the length of the search query you can use client side validation in SearchBox control.
    To do that you need to add a javascript function searchBoxClientValidationHandler in the page where the SearchBox is located.
    You might add the function in the master page:
    <head runat="server"
        <title></title
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />      
        <script language="javascript" type="text/javascript"
            var minLength = 4
            var maxLength = 10;      
             
            function searchBoxClientValidationHandler(textValue, searchBoxInstance) { 
                if (textValue.length < minLength || textValue.length > maxLength) { 
                    alert("Please enter a query between " + minLength + " and " + maxLength + " characters."); 
                    return false; 
                } 
                return true; 
            } 
        </script> 
    </head> 

    I hope this helps you.

    Kind regards,
    Parvan
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
  3. shraddha
    shraddha avatar
    87 posts
    Registered:
    18 May 2009
    19 Jun 2009
    Link to this post
    Hi Parvan,

    Thanx for the help.
    I am using searchBoxClientValidationHandler function on my page.
    Works properly in IE but in moziila it gives message after returning false and also gets redirected to the search result page.

    Also, I am calling another javascript function on click of go button. Which works fine when I type any text in search box but when and paste any text in search box it shows results for previously typed text.

    Please reply....
  4. Parvan
    Parvan avatar
    151 posts
    Registered:
    24 Sep 2012
    19 Jun 2009
    Link to this post
    Hello shraddha,

    The searchBoxClientValidationHandler function is invoked before the redirect to the search result page. If it returns false there is no redirect to search result page, otherwise the redirect is done.

    The message that is shown is caused by an alert statement in the function - just remove the alert and no message will be shown. It was added for testing purposes to the code sample.

    I will suggest you to use the searchBoxClientValidationHandler function instead of your function because this will guarantee that exactlyentered/pasted the text will be used. It accepts two parameters:
    • textValue - which is the exact text entered/pasted in the textbox.
    • searchBoxInstance - contains some additional properties like ResultUrl (the url to the search result page), Catalogue (the index name). For example searchBoxInstance.Catalogue will return the index name of the search box.

    I hope this helps you.

    Best wishes,
    Parvan
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
Register for webinar
4 posts, 0 answered