Credit Cards Masks

4 posts, 0 answers
  1. Jugoslav
    Jugoslav avatar
    72 posts
    Member since:
    Mar 2011

    Posted 15 Jan 2013 Link to this post

    I need to set the mask when they start to type e.g.
    if they enter 4 the mask should be 16 digits split into 4 groups of 4 digits each #### #### #### #### - VISA
    if they enter number 51-55 the mask should be same as above - MASTERCARD
    if they enter 6011 or 65 the mask should be same with the previous two - DISCOVER
    if they enter 34 or 37 the last group should be 3 character instead (15 in total) - AMEX

    Thank you

    EDIT: In addition, the very same regex which works for regular textbox does not work (ONLY AMEX) for Masked textbox:
    <telerik:RadMaskedTextBox ID="txtCCNumber" runat="server"
            Mask="#### #### #### ####" ValidationGroup="CardValidate" />
                        <asp:RequiredFieldValidator ID="cardnumbervalidator" runat="server"
                            ControlToValidate="txtCCNumber" ErrorMessage="Card Number is Required!"
                            SetFocusOnError="True" ValidationGroup="CardValidate">!</asp:RequiredFieldValidator>
                        <asp:RegularExpressionValidator ID="cardregvalidator" runat="server"
                            ControlToValidate="txtCCNumber" ErrorMessage="Card Number is not valid!"
                            ValidationExpression="^((4\d{3})|(5[1-5]\d{2})|(6011))-?\d{4}-?\d{4}-?\d{4}|3[4,7][\d\s-]{13}$" ValidationGroup="CardValidate">!</asp:RegularExpressionValidator>
  2. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 17 Jan 2013 Link to this post

    Hello Jugoslav,

    I think you're better off using the standard RadTextBox because it almost sounds like it's returning the last digit as a space, thus the reason your regular expression doesn't work for AMEX.
  3. Kostadin
    Kostadin avatar
    1733 posts

    Posted 21 Jan 2013 Link to this post

    Hello Jugoslav,

    Another solution is to use two RadMaskedTextBoxes. When you choose the card type you can check which one is selected and switch to the RadMaskedTextBoxe which meet the requirement.

    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.
  4. Manahil
    Manahil avatar
    2 posts
    Member since:
    Jan 2019

    Posted 23 Jan Link to this post

    I also wanted to know how I can use MASTERCARD in Telerik?
Back to Top