Hexadecimal digits in MaskedTextInput - autoconvert to Uppercase

4 posts, 1 answers
  1. Kornelije
    Kornelije avatar
    28 posts
    Member since:
    May 2011

    Posted 03 Dec 2012 Link to this post

    I need a masked text input to handle hexadecimal characters, of required length 6.
    For example: 334CFA, 1CA039 or CA377F.

    However, I have two requirements:

    - User should be able to enter both lowercase and uppercase letters A-F
    - The control would display only uppercase letters, even when a lowercase letter is entered.

    So, user should be able to enter 15cfaD (written without shift/capslock), and the control should display: 15CFAD. The control should never display lowercase letters, but it should allow them to be input, automatically converting them to uppercase.

    I've tried with a custom token, but I was only able to limit the input to 0-9A-Fa-f. This of course does not make the control display lowercase letters as uppercase.

    I've tried using uppercase modifier (>) with my custom token X (Mask = ">X>X>X>X>X>X"), but it did not modify the token, it simply inserted the > characters into the input.

    Is there any way to implement a custom token with TokenType.Modifier that would change the token with an arbitrary function?

    How can I achieve the scenario described?
  2. Answer
    Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 05 Dec 2012 Link to this post

    Hi Kornelije,

    You are using the correct approach to restrict the user's input. By creating a custom token you can define a custom list of symbols as a valid input. In your case these symbols are "abcdef1234567890ABCDEF". Also you need to restrict the length of the alpha-numeric string. You can do this by setting the mask to "******" or "*6" or you can use our extensions to limit the length of the input. You can read more about our extensions here.

    After creating the token (by following this article) you can use modifiers to make the text uppercase only. You can do this by setting the Mask property of the RadMaskedTextInput control to ">*6". As you can see the ">" sign is escaped and this will uppercase the user's input. I have created a sample project demonstrating the approach. Please take a look at it and let me know if it works for you.

    Regards,
    Pavel R. Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Kornelije
    Kornelije avatar
    28 posts
    Member since:
    May 2011

    Posted 10 Dec 2012 Link to this post

    The only difference between your code and mine was the ITokenValidationRule.IsRequired property.

       I have set it to TRUE, because I needed all 6 characters entered. However, what happened is that the lowercase characters were converted to uppercase only when all required characters were entered (although I believe that the last character triggers the change). I needed an instant change, and it wasn't happening.

     In addition to setting the MaskedInputExtensions.MinTextLength and MaskedInputExtensions.MaxTextLength to 6, I then tried to set the IsRequired to FALSE, just as you did, and this solved the problem.

    Would you be so kind as to explain why does setting the IsRequired property to one value or the other changes the behavior of the control in this way. 

    Thanks
  5. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 12 Dec 2012 Link to this post

    Hello Kornelije,

    Thank you for bringing this issue to our attention. I have logged it as a bug in our PITS and you can follow and vote for it here. Also I have updated your Telerik account accordingly.

    Regards,
    Pavel R. Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top