How to Validate New Custom Entries.

5 posts, 0 answers
  1. Eric
    Eric avatar
    37 posts
    Member since:
    Aug 2012

    Posted 19 Feb 2013 Link to this post


    I have the AllowCustomEntry set to true and I have the following scenario:
    If the new Entry is an Email (has an email format) then add it normally, if the new Entry is not an email then
    Check if the New Entry Exists in the DataSource/ENtryCollection, if it Exists then Do Nothing, if it doesn't exist
    then I need to set the Background Color of the new Entry to Red.

    This is what I have so far:

    <script type="text/javascript">
        function OnClientEntryAdded(sender, eventArgs) {

            var newEntry = eventArgs.get_entry().get_text();
            if (validateEmail(newEntry)) {
                 // If New Custom Entry is an Emeail Do Nothing
            else {
    // ELSE
    // If New Custom Entry is Not an Email and It Does Not Exist in the 
    // DataSource/Items then I want the New Added Entry to have a RED
    // Background Color so that it indicates that the Entry is incorrect.
    // IF newEntry does NOT exist in the EntryCollection THEN
    // Change the Background COlor of the New ENtry to Red
        function validateEmail(email) {
            var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
            return re.test(email);

    I also need to know how to use the remove() entry function within that event.

  2. Eric
    Eric avatar
    37 posts
    Member since:
    Aug 2012

    Posted 20 Feb 2013 Link to this post

    Any help would be appreciated, thank you, I have looked at the client side programming functions but I still was unable to achieve what I wanted so I need your help.
  3. Eric
    Eric avatar
    37 posts
    Member since:
    Aug 2012

    Posted 21 Feb 2013 Link to this post

    Should I submit this ti a support ticket? I haven't seen much help for this control in the documentation, 
  4. Nencho
    Nencho avatar
    1662 posts

    Posted 22 Feb 2013 Link to this post

    Hello Eric,

    The datasource, which the RadAutoCompleteBox  is populated with, is not accessible at client-side.This is because the datasource is based on the typed in the input text. Each time a character is typed, a new request to the database is initiated, in order to retrieve the corresponding data. Therefor, I can suggest you to verify the entered token and check if it is present in the datasource at server-side. You could use the OnEntryAdded and assign a value to the entry, which did not met the validation. In addition, at OnClientLoad you could loop through all entries set the background color for those with the above mentioned value. Please consider the following implementation:

    protected void RadAutoCompleteBox_EntryAdded(object sender, AutoCompleteEntryEventArgs e)
          //perfomr validation here.
          e.Entry.Value = "notValid";

    <script type="text/javascript">
         function onClientLoad(sender) {
             var entries = sender.get_entries();
             var entriesCount = entries.get_count()
             for (var i = 0; i < entriesCount; i++) {
                 var entry = entries.getEntry(i);
                 if (entry.get_value() == "notValid") {
                     entry.get_token().style.backgroundColor = "Red"

    <style type="text/css">
            html .RadAutoCompleteBox_Default .racToken {
                background-image: none;

    Kind regards,
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  5. Eric
    Eric avatar
    37 posts
    Member since:
    Aug 2012

    Posted 22 Feb 2013 Link to this post

    Hello Nencho
    Thanks for the hlep and the suggestions
    If I add the "RadAutoCompleteBox_EntryAdded" event to RadAutoComplete that would
    cause a postback each time an entry
    is added which is not a desired behavior, I don't want to access the Data Source per se 
    In code behind I access the Entries collection like so:

    AutoCompleteBoxEntryCollection bccEntryCollection = MailBCCAutoComplete.Entries;

    I want to access the Entries collection from client.

    If that also isn't possible the only thing that comes to mind is using jQuery Ajax, get the
    DataSource from there and then make the comparison client side.

Back to Top