custom validation

2 posts, 0 answers
  1. Lovella Bacaud
    Lovella Bacaud avatar
    20 posts
    Member since:
    Apr 2013

    Posted 19 Sep 2013 Link to this post

    Hi telerik

    Can I perform mathematical validation using radcaptcha? Ex. 3+2=? like this.

    Any help appreciated
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Sep 2013 Link to this post

    Hi Lovella,

    RadCaptcha supports custom validation. Please have a look at the sample code I tried which works fine at my end.

    <telerik:RadCaptcha ID="RadCaptcha1" runat="server" CaptchaImage-TextChars="Numbers"
        ValidationGroup="CaptchaValidation" CaptchaImage-RenderImageOnly="true" CaptchaImage-TextLength="3"
        ErrorMessage="Wrong" CaptchaTextBoxLabel="Enter Sum of Digits" OnCaptchaValidate="RadCaptcha1_CaptchaValidate">
    <telerik:RadTextBox ID="RadTextBox1" runat="server">
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ValidationGroup="CaptchaValidation"
        ControlToValidate="RadTextBox1" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
    <br />
    <telerik:RadButton ID="RadButton1" runat="server" ValidationGroup="CaptchaValidation"

    protected void Page_Init(object sender, EventArgs e)
        if (!IsPostBack)
            Session["CaptchaCode"] = RadCaptcha1.CaptchaImage.Text;
    protected void RadCaptcha1_CaptchaValidate(object sender, CaptchaValidateEventArgs e)
        e.CancelDefaultValidation = true;
        string captcha = Session["CaptchaCode"].ToString();
        int digitsSum = 0;
        foreach (char c in captcha)
            digitsSum += Convert.ToInt32(c.ToString());
        int enteredsum = Convert.ToInt32(RadTextBox1.Text);
        if (digitsSum == enteredsum)
            e.IsValid = true;
            e.IsValid = false;
        Session["CaptchaCode"] = RadCaptcha1.CaptchaImage.Text;

  3. DevCraft R3 2016 release webinar banner
Back to Top