import { FormControl } from '@angular/forms' ; import * as Payment from 'payment' ; export class CreditCardValidator { param control static validateCardNumber ( control ) { if ( control ) { let isValid = Payment . fns . validateCardNumber ( control . value ) ; if ( ! isValid ) { return { "error" : "CREDIT_CARD_INVALID" } ; } } return null ; } param control static validateCardExpiry ( control ) { if ( control ) { let controlValue = control . value . split ( "/" ) ; let isValid = false ; if ( controlValue . length > 1 ) { let month = controlValue [ 0 ] . replace ( /^\s+|\s+$/g , '' ) ; let year = controlValue [ 1 ] . replace ( /^\s+|\s+$/g , '' ) ; isValid = Payment . fns . validateCardExpiry ( month , year ) ; } if ( ! isValid ) { return { "error" : "CREDIT_EXPIRY_INVALID" } ; } } return null ; } param control static validateCardCvc ( control ) { if ( control ) { let isValid = Payment . fns . validateCardCVC ( control . value ) ; if ( ! isValid ) { return { "error" : "CREDIT_CARD_INVALID" } ; } } return null ; } }