Mega Code Archive

 
Categories / JavaScript Tutorial / Regular Expressions
 

Matching a 16 digit credit card number separated by a single space

< 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>