Email Validation In RadTexbox Inside the Grid

2 posts, 0 answers
  1. Princia
    Princia avatar
    8 posts
    Member since:
    Oct 2011

    Posted 22 Feb 2012 Link to this post

    Hi All,

    I am uisng a RadTexbox for taking Email Address from user,which is inside the Radgrid's EditTemplate.I have used asp RegExpressionValidator for validating the user input.For inserting of new record in the grid the RegExpressionValidator is fired, if user enters the invalid email ID.Problem here is  that ,once  I save the record in grid   (by giving correct Email Address), then try to modify the Email Address the RegExpressionValidator is not fired for the invalid input.In other words I can put the problem like,for initial insert of email address RegExpressionValidator is fired for invalid input .If I try to modify Email address with invlaid data RegExpressionValidator  is not at all fired.I want client side validation for this problem.Please help me out in this regard.

    Thanks& Regards
  2. Nekud
    Nekud avatar
    4 posts
    Member since:
    May 2013

    Posted 08 Apr 2014 Link to this post

    Hey Princia,

    You can use the following client side validation for this.

    function ValidateEmail(field) {// field is the textbox.
                if (!checkEmail(field.value.replace(/ /g, ''))) {
                        alert("Invalid Email: " + emailArray[i]);
            function checkEmail(email){
                var regex = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;
                return regex.test(email);

    On your server side all you need to do is:
    protected void radGridAlerts_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
                    (e.Item.FindControl("txtEmail") as TextBox).Attributes.Add("onblur", "ValidateEmail(this)");

    This should validate the email once the textbox loses focus.

Back to Top