Matching a 16 digit credit card number separated by a single space : Credit Card « Regular Expressions « JavaScript Tutorial






<html>
<head>
<title>Matching a 16 digit credit card number separated by a single space</title>
<script type="text/javascript" language="javascript">
<!-- //
function IsMatchingCard(str){
   var myRegExp =  /[0-9]{4} [0-9]{4} [0-9]{4} [0-9]{4}/;
   return myRegExp.test(str)
}

function TestGuess(){

alert(IsMatchingCard("1234 1234 1234 1234"));
}
// -->
</script>
</head>
<body>
<h3>This page allows you to enter and check a 16 digit credit card number</h3>
<form>
<button type="Button" onclick="TestGuess()">
Click here to enter card number</button>
</form>
</body>
</html>








26.2.Credit Card
26.2.1.Matching a 16 digit credit card number separated by a single space
26.2.2.Matching a 16 digit credit card number with variable number of space characters
26.2.3.Validate Visa number
26.2.4.Validate MasterCard