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




       
        </telerik:RegExpTextBoxSetting>
       </telerik:RadInputManager>
       
       </form>
        <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 && emailid.search(/^\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 && emailid.search(/^\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 == "yahoo.co.in" || domain == "gmail.com") {
                            document.getElementById('lblemail').innerHTML = "This Domain (" + domain + ") has been Blocked.Please choose different Email Id";                      
                     }
                    args.IsValid = false;
                }
          


            }
            
        
        </script>




    ==========================================


    With Regards,
    Maha
  2. Tsvetina
    Admin
    Tsvetina avatar
    1874 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,
    Tsvetina
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top