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

Required validation for GridMaskedColumn

1 Answer 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nishanth
Top achievements
Rank 1
Nishanth asked on 08 Aug 2011, 07:39 PM
Hi,

I have a GridMaskedColumn in my RadGrid and in the edit mode, the Masked Textbox is supposed to take US phone number as input. I have added the following mask (###)###-#### to the GridMaskedColumn. But the problem is that its accepting space also. I want to display client side error/warning when the user does not enter all the 10 digits of the phone number and press on 'Update Button' so that the DB values are consistent. Is there any mask or any other way I can implement this client validation ?

Thanks,
Nishanth

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 11 Aug 2011, 02:45 PM
Hello Nishanth,

You can use a CustomValidator to see if the entered value fulfills the requirements and then dynamically change the textbox style, as shown below:
<asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="RadMaskedTextBox1"
    ClientValidationFunction="validate" ErrorMessage="Error " EnableClientScript="true"
    Display="Dynamic" />
<telerik:RadMaskedTextBox ID="RadMaskedTextBox1" runat="server" Mask="(###)###-###" />
<script type="text/javascript">
    function validate(source, eventArgs) {
        var textbox = $find(source.controltovalidate)
        var val = textbox.get_value();
        alert(val.length);
        if (val.length < 9) {
            textbox.get_styles().EnabledStyle[1] += " riError";
            textbox.updateCssClass();
            arguments.IsValid = false;
        }
        else {
            textbox.get_styles().EnabledStyle[1] = textbox.get_styles().EnabledStyle[1].replace("riError", "");
            textbox.updateCssClass();
            arguments.IsValid = true;
        }
    }


Regards,
Tsvetina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Nishanth
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or