Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

credit card regex javascript

function ValidateCreditCardNumber() {

  var ccNum = document.getElementById("cardNum").value;
  var visaRegEx = /^(?:4[0-9]{12}(?:[0-9]{3})?)$/;
  var mastercardRegEx = /^(?:5[1-5][0-9]{14})$/;
  var amexpRegEx = /^(?:3[47][0-9]{13})$/;
  var discovRegEx = /^(?:6(?:011|5[0-9][0-9])[0-9]{12})$/;
  var isValid = false;

  if (visaRegEx.test(ccNum)) {
    isValid = true;
  } else if(mastercardRegEx.test(ccNum)) {
    isValid = true;
  } else if(amexpRegEx.test(ccNum)) {
    isValid = true;
  } else if(discovRegEx.test(ccNum)) {
    isValid = true;
  }

  if(isValid) {
     alert("Thank You!");
  } else {
     alert("Please provide a valid Visa number!");
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: set onclick javascript 
Javascript :: get button text javascript 
Javascript :: javascript format number as currency 
Javascript :: socket io esm 
Javascript :: js convert nodelist to array 
Javascript :: how to get a randome element from a list in javascript 
Javascript :: javascript random boolean 
Javascript :: apply back button to a react component 
Javascript :: javascript moeda reais 
Javascript :: jquery select option auto select 
Javascript :: jquery grid get all selected row 
Javascript :: jquery sort select options by text 
Javascript :: copy directory in nodejs 
Javascript :: javascript pad number with leading zeros 
Javascript :: javascript get domain name from string 
Javascript :: js percorrer objeto 
Javascript :: how get a json object from an api in javascript 
Javascript :: updating react version 
Javascript :: convert to small case in javascript 
Javascript :: tailwind css calc 
Javascript :: Use Recursion to Create a Countdown 
Javascript :: componentdidmount hooks 
Javascript :: javascript string to integer 
Javascript :: jquery loop through list elements 
Javascript :: nodejs 16 install 
Javascript :: solid icons in next js 
Javascript :: window.history.pushstate typescript 
Javascript :: js get last 4 digits 
Javascript :: javascript on url anchor change event 
Javascript :: login to discord using token 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =