How to use validate custom JavaScript Function using RadInputManager

2 posts, 0 answers
  1. Maha
    Maha avatar
    3 posts
    Member since:
    Aug 2012

    Posted 27 Aug 2012 Link to this post

    Problem 1 : How to use validate custom JavaScript Function using RadInputManager
    I have TextBox which accept Email Id as Input 
    I want to validate following 

    V1)Must be Required Field
    V2)Must be valid Email Id
    V3)Domain Part should not matched with or etc
    V4)I want to check that email id in DataBase(Already registerd id or not)

    The above V1 and V2  i can achieve using 

    Validation-IsRequired="true"  ValidationExpression="^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$" ErrorMessage="Invalid Email"

    But instead of your code i want to validate using My JavaScript Code

    Current Now i'm displaying Error Message in Label

    But I want to show my Error Message inside TextBox

    I don't know how to get BehaviorID of txtemailid(textbox) and How i set My Custom Error Message inside TextBox

    I.e How can i access Validation-IsRequired and ErrorMessage Properties using script?

    Also As I mentioned Earlier I want to check that email id in DataBase(Already registerd id or not)..How can i achieve this using RadInputManager

    Please solve my problem..Thank You

    My ASPX
    <form id="form1" runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />

          <div id="divemail">
                <div style="width:150px; float:left; font-weight:bold;"><span style="color:Red;">*</span>&nbsp;Email Id</div>
                <div style=" width:235px; float:left;">
              <asp:TextBox ID="txtemailid" Width="150px" runat="server"></asp:TextBox>
                <div style=" float:left; height:10px; padding-left:10px;"> 
                    <asp:Label ID="lblemail" runat="server" ForeColor="#CC0000"></asp:Label> 
        <telerik:RadInputManager ID="RadInputManager1" runat="server">
       <telerik:RegExpTextBoxSetting ClientEvents-OnBlur="EmailValidate" BehaviorID="Regexemailid" runat="server" EmptyMessage="Email Id">
       <TargetControls><telerik:TargetInput  ControlID="txtemailid"/></TargetControls>

        <script type="text/javascript" language="javascript">

            function EmailValidate(sender, eventArgs) {
                document.getElementById('lblemail').innerHTML = "";
                var emailid = eventArgs.get_targetInput().get_value();
                if (emailid.length == 0)
                    document.getElementById('lblemail').innerHTML = "Required";

                    args.IsValid = false;
                //Invalid Email id
                else if (emailid.length > 0 &&^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
                    document.getElementById('lblemail').innerHTML = "Invalid Email ID";
                    args.IsValid = false;
                //This block has only Valid Email Ids--We have to check that domain
                else if (emailid.length > 0 &&^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
                   var domain = emailid.toLowerCase();
                       domain = domain.substring(emailid.indexOf("@") + 1, emailid.length);
                   if (domain == "" || domain == "") {
                            document.getElementById('lblemail').innerHTML = "This Domain (" + domain + ") has been Blocked.Please choose different Email Id";                      
                    args.IsValid = false;



    With Regards,
  2. Tsvetina
    Tsvetina avatar
    2481 posts

    Posted 30 Aug 2012 Link to this post

    Hello Maha,

    I am posting the reply from the support ticket that you opened with the same question here as well in case anyone else is interested:
    If you do not want to use the validation of RadInputManager, you could add CustomValidators to validate the TextBoxes and if they fail your check, set your error value. However, note that, as this validation is not performed by the manager itself, you cannot take advantage of the built-in ErrorMessage of the input settings, you should show your own.

    In case you have further questions about the input manager control, please post them in the support thread.

    All the best,
    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.
Back to Top