Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 3378
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 2, 20222022-06-02T11:42:43+00:00 2022-06-02T11:42:43+00:00

javascript – Credit card display order in textbox

  • 0

[ad_1]

Hi i am using material Ui React, I am able to detect what type of card is entered using below code but not able to restrict numbers to 15 or 16 whatever card type is and also if card is visa type i need to show= 4242 4242 4242 4242 like this but i am displaying plain 424242424242, how to display this. mainly i was looking for american express card display in textbox, Any help please
My code for detecting the card type is in “value2“:

 const onChange = (e) => {
      let value = e.target.value.replace(/\D/g, '')
      let value2;
      console.log(value)
      setInput({ ...input, [e.target.name]: value })
      // setInput({ ...input, [e.target.name]: e.target.value.replace(!/^[0-9]{14,16}$/) })

      const regexPattern = {
        MASTERCARD: /^5[1-5][0-9]{1,}|^2[2-7][0-9]{1,}$/,
        VISA: /^4[0-9]{2,}$/,
        AMERICAN_EXPRESS: /^3[47][0-9]{5,}$/,
        DISCOVER: /^6(?:011|5[0-9]{2})[0-9]{3,}$/,
        DINERS_CLUB: /^3(?:0[0-5]|[68][0-9])[0-9]{4,}$/,
        JCB: /^(?:2131|1800|35[0-9]{3})[0-9]{3,}$/
      };
      for (const card in regexPattern) {
        if (value.replace(/[^\d]/g, "").match(regexPattern[card]))
          value2 = card
      }
      console.log(value2)
    
  };

<TextField
              name="cardnumber"
              label="Card number"
              error={errors.cardnumber}
              value={input.cardnumber}
              onChange={onChange}
              helperText={errors.cardnumber && "Invalid card number"}
              className={classes.cardHolderNumberInputs}
            />

[ad_2]

  • 0 0 Answers
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 8143 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1925 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1960 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.