RadMaskedTextBox length validation?

9 posts, 0 answers
  1. Philip
    Philip avatar
    21 posts
    Member since:
    Nov 2008

    Posted 21 Oct 2009 Link to this post

    Hi,

    On radmaskedtextbox, I noticed that after setting the mask as Phone Number, it accepts numeric entries of 9 or less and won't throw that as an error, even though it's not a valid phone number length. Is there a way to set this on the control's properties? Or should I have to use a regular expression validator to achieve this? And also have the error message appear inside the radmaskedtext box like radinputmager does? (see 2nd scenario)

            <telerik:RadMaskedTextBox ID="RadMaskedTextBox1" Runat="server"
                DisplayMask="(###) ###-####" Mask="(###) ###-####"
                ValidationGroup="vgTest" ZeroPadNumericRanges="False"
                AllowEmptyEnumerations="False" DisplayPromptChar="#" RoundNumericRanges="False"
                Width="125px" NumericRangeAlign="Left">

    Another way I tried is to create a radinputmanager and set regular expression to phone number, this will validate on single numeric entries and we like the dynamic error messages appearing inside the textbox, however, the problem with this is we don't want the users to enter the ()- characters and we only want to grab the numeric entries to store in the database.

                <telerik:RegExpTextBoxSetting BehaviorID="Phone" ErrorMessage="Invalid Phone" ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}" Validation-ValidateOnEvent="Submit" Validation-IsRequired="true" Validation-ValidationGroup="vgTest">
                    <TargetControls>
                        <telerik:TargetInput ControlID="txtPhone" />
                    </TargetControls>

    Let me know which approach would achieve this. Sample codes appreciated. Thanks.
  2. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 27 Oct 2009 Link to this post

    Hi Philip,

    There is a straightforward way to implement your requirement using RadMaskedTextBox. You can use its client-side OnValueChanged event to check if your phone number is shorter than required, then set the error message yourself:

    <ClientEvents OnValueChanged="valueChanged" />

    function valueChanged(sender, args)
    {
        if (sender.get_value().length < 10)
        {
            setTimeout(function()
            {
                var eventArgs = new Telerik.Web.UI.MaskedTextBoxEventArgs(args.get_newValue(), args.get_oldValue(), null);
                sender.raise_error(eventArgs);
                sender.set_value("");
                sender._textBoxElement.value = "Invalid Phone";
            }, 0);
        }               
    }

    Check this piece out and let me know if it works for you.

    Kind regards,
    Veli
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Philip
    Philip avatar
    21 posts
    Member since:
    Nov 2008

    Posted 28 Oct 2009 Link to this post

    Thanks, Veli

    It works however I don't see the "Invalid Phone" value ever show, Is this because the RadMaskedTextBox is set to mask phone numbers and will only accept numeric inputs? So, I believe I may have to find an alternate way of displaying it, like on a tooltip.
  5. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 02 Nov 2009 Link to this post

    Hello Philip,

    I have omitted to specify that IE does not honor the value property of the HTML Input element. You need to use the innerText property instead:

    function valueChanged(sender, args)
    {
        if (sender.get_value().length < 10)
        {
            setTimeout(function()
            {
                var eventArgs = new Telerik.Web.UI.MaskedTextBoxEventArgs(args.get_newValue(), args.get_oldValue(), null);
                sender.raise_error(eventArgs);
                sender.set_value("");
                 
                sender._textBoxElement.value = "Invalid Phone";
                sender._textBoxElement.innerText = "Invalid Phone";
            }, 0);
        }               
    }


    Greetings,
    Veli
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Shif
    Shif avatar
    5 posts
    Member since:
    Jun 2012

    Posted 07 Feb 2012 Link to this post

    Hi,
    My MaskedTextBox is short,
    How can I Show a Long Message?

    Thanks
    Shif
  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 Feb 2012 Link to this post

    Hello,

    I am not quite sure about your scenario. I suppose you need to show large Mask in RadMaskedTextBox. One suggestion is you can try setting Width  for RadMaskedTextBox based on your mask.

    Thanks,
    Princy.
  8. Shif
    Shif avatar
    5 posts
    Member since:
    Jun 2012

    Posted 07 Feb 2012 Link to this post

    Hi,
    Thanks for your reply,

    <

     

    telerik:RadMaskedTextBox ID="tbtry" runat="server" SelectionOnFocus="SelectAll"

     

     

    PromptChar=" " Mask="<00..48>:<00..59>" Width="30px" ZeroPadNumericRanges="true" >

     

     

    <ClientEvents OnValueChanged ="houresCheck" />

     

     

     

    </telerik:RadMaskedTextBox>

     

     


    I have a RadMaskedTextBox is quite short, - and this is how I need it, but when I put an unvalied value I want to show a long message -  not in a messagebox is there any way?

    or even better for me if I click 7 - it should write 07:00 - and not like now that it writes 48:00 - How can I do it?
    Thanks,
    Shif
  9. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Feb 2012 Link to this post

    Hello,

    Try setting RoundNumericRanges property of RadMaskedTextBox as false.

    Thanks,
    Princy.
  10. Shif
    Shif avatar
    5 posts
    Member since:
    Jun 2012

    Posted 08 Feb 2012 Link to this post

    Hi Princy,
    It solved my problem!!

    Lots of Thanks!

    Shif
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017