@@ -8,6 +8,68 @@ Angular2 CC Library - for validation and formating of input parameters
8
8
3 . run ` npm run dev `
9
9
4 . visit ` http://localhost:4200 `
10
10
11
+ # Usage
12
+
13
+ ## Formating Directive
14
+ On the input fields, add the specific directive to format inputs.
15
+ All fields must be ` type='tel' ` in order to support spacing and additional characters
16
+
17
+ ** Credit Card Formater**
18
+ * add ` ccNumber ` directive:
19
+ ```
20
+ <input id="cc-number" type="tel" autocomplete="cc-number" ccNumber>
21
+ ```
22
+
23
+ ** Expiration Date Formater**
24
+ Will support format of MM/YY or MM/YYYY
25
+ * add ` ccExp ` directive:
26
+ ```
27
+ <input id="cc-exp-date" type="tel" autocomplete="cc-exp" ccExp>
28
+ ```
29
+
30
+ ** CVC Formater**
31
+ * add ` ccCvc ` directive:
32
+ ```
33
+ <input id="cc-cvc" type="tel" autocomplete="off" ccCvc>
34
+ ```
35
+
36
+ ### Validation
37
+ Current only Model Validation is supported.
38
+ To implement, import the validator library and apply the specific validator on each form control
39
+ ```
40
+ import { CreditCardValidator } from '../../src/validators/credit-card.validator';
41
+
42
+ @Component({
43
+ selector: 'app',
44
+ template: `
45
+ <form #demoForm="ngForm" (ngSubmit)="onSubmit(demoForm)" novalidate>
46
+ <input id="cc-number" formControlName="creditCard" type="tel" autocomplete="cc-number" ccNumber>
47
+ <input id="cc-exp-date" formControlName="expirationDate" type="tel" autocomplete="cc-exp" ccExp>
48
+ <input id="cc-cvc" formControlName="cvc" type="tel" autocomplete="off" ccCvc>
49
+ </form>
50
+ `
51
+ })
52
+ export class AppComponent implements OnInit {
53
+ form: FormGroup;
54
+ submitted: boolean = false;
55
+
56
+ constructor(private _fb: FormBuilder) {}
57
+
58
+ ngOnInit() {
59
+ this.form = this._fb.group({
60
+ creditCard: ['', [<any>CreditCardValidator.validateCCNumber]],
61
+ expirationDate: ['', [<any>CreditCardValidator.validateExpDate]],
62
+ cvc: ['', [<any>Validators.required, <any>Validators.minLength(3), <any>Validators.maxLength(4)]]
63
+ });
64
+ }
65
+
66
+ onSubmit(form) {
67
+ this.submitted = true;
68
+ console.log(form);
69
+ }
70
+ }
71
+ ```
72
+
11
73
# Inspiration
12
74
13
75
Based on Stripe's [ jquery.payment] ( https://github.com/stripe/jquery.payment ) plugin but adapted for use by Angular2
18
80
19
81
# TODO
20
82
- [ ] Documentation
21
- - [ ] Tests
83
+ - [x] Unit Tests
84
+ - [ ] Protractor Tests
22
85
- [ ] Validate cvc input length against value from card object
23
86
- [ ] publish to NPM
0 commit comments