I saw this code and tried adding that into my code.
function validate_creditcardnumber() { var re16digit=/^\\d{16}$/ if (CreditCardNumber.value.search(re16digit)==-1) alert("Please enter your 16 digit credit card numbers"); return false; }
My code below:
function confirmSubmit()
{
var re16digit = /^\d{16}$/
if (document.getElementById("txtCreditCardNumber").value == "" ||
isNaN(document.getElementById("txtCreditCardNumber").value) ||
(document.getElementById("txtCreditCardNumber").value.search(re16digit) == -1)) {
alert("Credit Card number must be a numeric value.");
document.getElementById("txtCreditCardNumber").focus();
return false;
}
return true;
}
There wasn't any error shown but when I ran the code, only the .value == " " was working. The other 2 didn't work. I need to have these requirements: Cannot be empty, must be a number and must be 16 digits. Thanks in advance!
dont put together, separate it. after //your alert("Credit Card number must be a numeric value."); document.getElementById("txtCreditCardNumber").focus(); return false; }
//// create the VAR & add in the{ code }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.