This is a migrated thread and some comments may be shown as answers.

RadMaskedTextBox Validations

4 Answers 107 Views
Input
This is a migrated thread and some comments may be shown as answers.
Devang
Top achievements
Rank 1
Devang asked on 07 Aug 2012, 07:57 AM

<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 

4 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 07 Aug 2012, 08:12 AM
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.
0
Devang
Top achievements
Rank 1
answered on 07 Aug 2012, 08:38 AM
Thanks Vasil
Devang Tadvi
0
Tarang
Top achievements
Rank 1
answered on 22 Oct 2013, 01:18 PM
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
0
Vasil
Telerik team
answered on 22 Oct 2013, 02:07 PM
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.
Tags
Input
Asked by
Devang
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Devang
Top achievements
Rank 1
Tarang
Top achievements
Rank 1
Share this question
or