0

PLEASE HELP!! I cant figure out how to have chosen credit card type to have prefix numers at start validated with javascript

if (document.orderform.CreditCardNumber.value.length < 16) { //Checking the card number is 16 digits alert("Sorry, You need to enter Your Credit Card Number. It must be 16 digits!") return false }               for (var i=0;i<document.orderform.CreditCardNumber.value.length;i++){ temp=document.orderform.CreditCardNumber.value.substring(i,i+1) if (digits.indexOf(temp)==-1){ alert("Invalid Credit Card Number, Only use Numbers, It must be 16 digits!") return false } }

6th Sep 2017, 9:19 AM
Callan Wright
Callan Wright - avatar
1 Antwort
+ 1
Try this function function checkNum(numString) { var re= new RegExp(/^\d{16}$/); if(!numString.match(re)) { console.log("16 numbers are required"); return false } console.log("16 numbers entered"); return true; } checkNum(document.orderForm.creditCardNumber.value);
6th Sep 2017, 9:39 AM
Calviղ
Calviղ - avatar