RadMaskedTextBox Validations

5 posts, 0 answers
  1. Devang
    Devang avatar
    7 posts
    Member since:
    Aug 2012

    Posted 07 Aug 2012 Link to this post

    <telerik:RadMaskedTextBox ID="zipRMTB" runat="server" EmptyMessage="Zip Code"

    Mask="##### - ####" SelectionOnFocus="SelectAll">

    </telerik:RadMaskedTextBox>

    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="zipRMTB"

    ErrorMessage="RequiredFieldValidator">

    </asp:RequiredFieldValidator>
    Here, i am trying  to validate RadMaskedTexBox,on btn click event it doent show validate errormessage,

    and another problem is:
     if i will insert incorrect data into MaskedTextBox like:  _32_ - 1__0
      how to validate these type of data with Validators??

    Thank You 
    Devang Tadvi 

  2. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 07 Aug 2012 Link to this post

    Hello Devang,

    From Q2 2012, you can set RequireCompleteText="true" for the RadMaskedTextBox, and and it will require full text to be entered in order to pass value to the RequiredFieldValidator different than empty string.

    Greetings,
    Vasil
    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
  4. Devang
    Devang avatar
    7 posts
    Member since:
    Aug 2012

    Posted 07 Aug 2012 Link to this post

    Thanks Vasil
    Devang Tadvi
  5. Tarang
    Tarang avatar
    11 posts
    Member since:
    Jun 2013

    Posted 22 Oct 2013 Link to this post

    Hi Vasil,

    RequireCompleteText="true" also validates empty values. I do not want to validate if user does not put any thing in it. Is there any property available for it??

    Look at attached image. 

    Here is my skin for ZipExtension text Box:

    <telerik:RadMaskedTextBox SkinID="sknZipExt" runat="server" Width="50px" MaxLength="4" Mask="####" SelectionOnFocus="SelectAll" RequireCompleteText="true"  />

    Is there other way to validate this is except using regular expression validator and validate entire text.

    Thanks,
    Tarang Pandya
  6. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 22 Oct 2013 Link to this post

    Hi Tarang,

    Well it is not supported out of the box.
    But you could override some methods in order to make it work. Here is the original code, and you can add an additional checks as per your requirements:

        Telerik.Web.UI.RadMaskedTextBox.prototype._constructValidationText= function (value)
    {
        if (this.get_value() && !(this._requireCompleteText && this.get_valueWithPromptAndLiterals() != this.get_valueWithLiterals())) //add additional checks here
        {
            return this.get_valueWithLiterals();
        }
        else
        {
            return "";
        }
    }
    Telerik.Web.UI.RadMaskedTextBox.prototype.raise_valueChanged= function ()
    {  
        this._triggerDomEvent("change", this._textBoxElement);
        this._holdsValidValue = true;
        if (this._requireCompleteText)
        {
            if (this.get_valueWithPromptAndLiterals() != this.get_valueWithLiterals())
            {
                //add additional checks here
                return this._invalidate();
            }
        }
        var tempOldValue = this._textBoxElement._oldValue;
        this._textBoxElement._oldValue = this._textBoxElement.value;
        this._OnValueChange(null, tempOldValue, this._textBoxElement.value);
     
    }

    Also you may want to override the function ValidationText of server side RadMaskedTextBox class. Its current code is:
    public override string ValidationText
     {
         get
         {
             if (String.IsNullOrEmpty(Text) ||
                 (this.RequireCompleteText && (TextWithPromptAndLiterals.Length != TextWithLiterals.Length)))
             {
                 return String.Empty;
             }
             return TextWithLiterals;
         }
     }


    Regards,
    Vasil
    Telerik
    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 the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017