woodplease Posted December 4, 2009 Share Posted December 4, 2009 hi. i want to be able to check that a users inputted card number is 16 digits in length, but i cant seem to be able to do it. Just a simple javascript function is all i really need Any help would be great, thanks. Link to comment https://forums.phpfreaks.com/topic/183984-text-box-length-validation/ Share on other sites More sharing options...
KevinM1 Posted December 4, 2009 Share Posted December 4, 2009 function checkCreditCard(cardNum) { var regEx = /^\d{16}$/; if (!cardNum.match(regEx)) { alert("Credit card number must contain 16 digits"); return false; } else { return true; } } Note that this assumes that the proper pattern for cardNum is simply a string of 16 digits without hyphens or spaces. Link to comment https://forums.phpfreaks.com/topic/183984-text-box-length-validation/#findComment-971338 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.