Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

crdit card input format

var myInput = document.querySelector("#myInput");
myInput.addEventListener("input", updateFunpassInputCode);
function updateInputCode(e) {
    var cardNumber = myInput.value;

	  // Do not allow users to write invalid characters
    var formattedCardNumber = cardNumber.replace(/[^d]/g, "");
    var formattedCardNumber = formattedCardNumber.substring(0, 12);

    // Split the card number is groups of 4
    var cardNumberSections = formattedCardNumber.match(/d{1,4}/g);
    if (cardNumberSections !== null) {
        formattedCardNumber = cardNumberSections.join('-');
    }

    // If the formmattedCardNumber is different to what is shown, change the value
    if (cardNumber !== formattedCardNumber) {
        myInput.value = formattedCardNumber;
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to check is the key of a localstorage is emopty 
Javascript :: react router dom default params 
Javascript :: git reset local branch to origin 
Javascript :: autocomplete required material ui 
Javascript :: hover javascript 
Javascript :: apollo uselazyquery oncompleted 
Javascript :: js code to accept all linkedin requests 
Javascript :: header react native 
Javascript :: mariadb javascript 
Javascript :: can we get the value of form control after disabling it angular 
Javascript :: usememo 
Javascript :: click on browser.find_element_by_xpath with href 
Javascript :: javascript get name from steamid 
Javascript :: how to convert string to invert case in javascript 
Javascript :: react native swipe screen 
Javascript :: javascript close calendar after select 
Javascript :: lodash uniqby 
Javascript :: clone canvas 
Javascript :: run a local instance of ElasticSearch on docker 
Javascript :: react return multiple components 
Javascript :: delay / sleep program in js 
Javascript :: postfix date javascript 
Javascript :: onclick automatically called after 10 seconds 
Javascript :: Calendar Time momentjs 
Javascript :: order by type 
Javascript :: disable livewire error model 
Javascript :: what is react mounting 
Javascript :: getx navigation 
Javascript :: javascript tousand seperator 
Javascript :: sending api request in axios with files 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =