Display warning on invalid entry

3 posts, 1 answers
  1. Merlin
    Merlin avatar
    15 posts
    Member since:
    Feb 2013

    Posted 25 Feb 2013 Link to this post

    Hi,

    I am using a RadDatepicker in my form. I want to display a warning near the RadDatePicker if some invalid character is entered?

    Thank you,
    Merlin.
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Feb 2013 Link to this post

    Hi Merlin,

    I guess you want to display a warning icon inside the Textbox of RadDatePicker when the user type some invalid character. Please have a look at the following code in which a warning is shown inside the TextField when the user press any alphabetic keys.

    ASPX:
    <telerik:RadDatePicker ID="RadDatePicker1" runat="server" onKeyPress="return checkInput(event);"
        onKeyDown="return checkInput(event);">
    </telerik:RadDatePicker>

    JavaScript:
    <script type="text/javascript">
        function checkInput(event) {
            var DatePicker = $find("<%= RadDatePicker1.ClientID %>");
            if (event.keyCode >= 65 && event.keyCode <= 90) {
                //checking if the key pressed is an alpahbetic key
                DatePicker.get_dateInput()._invalid = true;
                DatePicker.get_dateInput().updateCssClass();
                //For not showing the alphabet in the textbox and display the warning.
                return false;
            }
            else {
                DatePicker.get_dateInput()._invalid = false;
                DatePicker.get_dateInput().updateCssClass();
                return true;
            }
        }
    </script>

    Thanks,
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Merlin
    Merlin avatar
    15 posts
    Member since:
    Feb 2013

    Posted 26 Feb 2013 Link to this post

    Thanks for the sample code. I made a little modification and got it working as expected.
Back to Top