File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 1- function creditCardValidator ( cardNumber ) { }
1+ function creditCardValidator ( cardNumber ) {
2+ // Remove all - and spaces from the input
3+ const sanitized = cardNumber . replace ( / [ - \s ] / g, "" ) ;
4+
5+ //check if the length of the sanitized input is 16
6+ if ( sanitized . length !== 16 ) {
7+ return false ;
8+ } else {
9+ return true ;
10+ }
11+ }
12+
13+ module . exports = creditCardValidator ;
Original file line number Diff line number Diff line change 1+ const creditCardValidator = require ( "./creditCard-validator" ) ;
2+
3+ describe ( "creditCardValidator" , ( ) => {
4+ test ( "should return true for a 16 digit long card number" , ( ) => {
5+ expect ( creditCardValidator ( "1234-5678-9012-3456" ) ) . toBe ( true ) ;
6+ expect ( creditCardValidator ( "1234 5678 9012 3456" ) ) . toBe ( true ) ;
7+ } ) ;
8+ } ) ;
You can’t perform that action at this time.
0 commit comments