Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to remove the input whitespaces when entering a card number? #485

Open
stanleynik opened this issue Feb 21, 2021 · 2 comments
Open

How to remove the input whitespaces when entering a card number? #485

stanleynik opened this issue Feb 21, 2021 · 2 comments
Labels
question workaround A workaround has been provided

Comments

@stanleynik
Copy link

But I would like to keep the whitespaces in the card

@melloware
Copy link
Collaborator

There is nothing built in so you will have to code this yourself in Javascript

@NikhilMali-98
Copy link

To remove whitespaces from a card number input in a programming language like JavaScript, we can use the replace function to replace all whitespace characters with an empty string.

Example :
// Assuming cardNumber is the input containing whitespace
let cardNo = "1234 5678 9012 3456";

// Remove whitespaces
let cleanedCardNo = cardNumber.replace(/\s/g, '');

console.log(cleanedCardNo);

In this example, the regular expression \s matches any whitespace character, and the g flag ensures a global search, replacing all occurrences. The result is a card number without any whitespaces.

@melloware melloware added the workaround A workaround has been provided label Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question workaround A workaround has been provided
Projects
None yet
Development

No branches or pull requests

3 participants