Skip to content

Commit

Permalink
feat: support libphonenumber yuyang041060120#23
Browse files Browse the repository at this point in the history
  • Loading branch information
jacky.yyy committed Apr 10, 2017
1 parent 4bb85d4 commit 0eaeb39
Show file tree
Hide file tree
Showing 47 changed files with 312 additions and 393 deletions.
28 changes: 2 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,35 +193,11 @@ export class AppModule {
### phone

```html
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" [phone]="'zh-CN'"/>
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" phone="CN"/>
<p *ngIf="field.errors?.phone">error message</p>
```

*default*: en-US

**support**

- de-CH
- de-DE
- el-GR
- en-AU
- en-GB
- en-HK
- en-NZ
- en-US
- en-ZA
- en-ZM
- fr-FR
- hu-HU
- nb-NO
- nl-NL
- nn-NO
- pt-BR
- pt-PT
- ru-RU
- vi-VN
- zh-CN
- zh-TW
details see [libphonenumber](https://github.com/halt-hammerzeit/libphonenumber-js)

### uuid

Expand Down
36 changes: 6 additions & 30 deletions bundles/ng2-validation.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bundles/ng2-validation.umd.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/dist/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/dist/bundle.js.map

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions example/dist/polyfills.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/dist/polyfills.js.map

Large diffs are not rendered by default.

106 changes: 53 additions & 53 deletions example/dist/vendor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/dist/vendor.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './src/app.module';

Expand Down
100 changes: 50 additions & 50 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
module.exports = function (config) {
var _config = {
basePath: './',

frameworks: ['jasmine'],

files: [
{pattern: './karma-test-shim.js', watched: false}
],

preprocessors: {
'./karma-test-shim.js': ['webpack', 'sourcemap']
},

webpack: {
resolve: {
extensions: ['', '.ts', '.js']
},
module: {
loaders: [
{
test: /\.ts$/,
loader: 'ts'
},
{
test: /\.html$/,
loader: 'raw'
}
]
}
},

webpackMiddleware: {
stats: 'errors-only'
},

webpackServer: {
noInfo: true
},

reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['PhantomJS'],
singleRun: true
};

config.set(_config);
module.exports = function(config) {
var _config = {
basePath: './',

frameworks: [ 'jasmine' ],

files: [
{ pattern: './karma-test-shim.js', watched: false }
],

preprocessors: {
'./karma-test-shim.js': [ 'webpack', 'sourcemap' ]
},

webpack: {
resolve: {
extensions: [' ', '.js', '.ts']
},
module: {
loaders: [
{
test: /\.ts$/,
loader: 'ts-loader'
},
{
test: /\.html$/,
loader: 'raw-loader'
}
]
}
},

webpackMiddleware: {
stats: 'errors-only'
},

webpackServer: {
noInfo: true
},

reporters: [ 'progress' ],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: [ 'PhantomJS' ],
singleRun: true
};

config.set(_config);
};
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,8 @@
"webpack": "^2.3.2",
"webpack-dev-server": "^2.4.2",
"zone.js": "^0.8.4"
},
"dependencies": {
"libphonenumber-js": "^0.4.5"
}
}
2 changes: 1 addition & 1 deletion src/base64/validator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbstractControl, Validators, ValidatorFn } from '@angular/forms';

import { isPresent } from '../facade/lang';
import { isPresent } from '../util/lang';

export const base64: ValidatorFn = (control: AbstractControl): {[key: string]: boolean} => {
if (isPresent(Validators.required(control))) return null;
Expand Down
2 changes: 1 addition & 1 deletion src/credit-card/validator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbstractControl, Validators, ValidatorFn } from '@angular/forms';

import { isPresent } from '../facade/lang';
import { isPresent } from '../util/lang';

export const creditCard: ValidatorFn = (control: AbstractControl): {[key: string]: boolean} => {
if (isPresent(Validators.required(control))) return null;
Expand Down
2 changes: 1 addition & 1 deletion src/date-ios/validator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbstractControl, Validators, ValidatorFn } from '@angular/forms';

import { isPresent, isDate } from '../facade/lang';
import { isPresent, isDate } from '../util/lang';

export const dateISO: ValidatorFn = (control: AbstractControl): {[key: string]: boolean} => {
if (isPresent(Validators.required(control))) return null;
Expand Down
2 changes: 1 addition & 1 deletion src/date/validator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbstractControl, Validators, ValidatorFn } from '@angular/forms';

import { isPresent, isDate } from '../facade/lang';
import { isPresent, isDate } from '../util/lang';

export const date: ValidatorFn = (control: AbstractControl): {[key: string]: boolean} => {
if (isPresent(Validators.required(control))) return null;
Expand Down
2 changes: 1 addition & 1 deletion src/digits/validator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbstractControl, Validators, ValidatorFn } from '@angular/forms';

import { isPresent } from '../facade/lang';
import { isPresent } from '../util/lang';

export const digits: ValidatorFn = (control: AbstractControl): {[key: string]: boolean} => {
if (isPresent(Validators.required(control))) return null;
Expand Down
2 changes: 1 addition & 1 deletion src/email/validator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbstractControl, Validators, ValidatorFn } from '@angular/forms';

import { isPresent } from '../facade/lang';
import { isPresent } from '../util/lang';

export const email: ValidatorFn = (control: AbstractControl): {[key: string]: boolean} => {
if (isPresent(Validators.required(control))) return null;
Expand Down
2 changes: 1 addition & 1 deletion src/equal/validator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbstractControl, Validators, ValidatorFn } from '@angular/forms';

import { isPresent } from '../facade/lang';
import { isPresent } from '../util/lang';

export const equal = (val: any): ValidatorFn => {
return (control: AbstractControl): {[key: string]: any} => {
Expand Down
1 change: 1 addition & 0 deletions src/greater-than-equal/directive.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// todo
42 changes: 42 additions & 0 deletions src/greater-than-equal/directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Directive, Input, forwardRef, OnInit, OnChanges, SimpleChanges } from '@angular/core';
import { NG_VALIDATORS, Validator, ValidatorFn, AbstractControl } from '@angular/forms';

import { gt } from './';

const GREATER_THAN_VALIDATOR: any = {
provide: NG_VALIDATORS,
useExisting: forwardRef(() => GreaterThanValidator),
multi: true
};

@Directive({
selector: '[gt][formControlName],[gt][formControl],[gt][ngModel]',
providers: [GREATER_THAN_VALIDATOR]
})
export class GreaterThanValidator implements Validator, OnInit, OnChanges {
@Input() gt: number;

private validator: ValidatorFn;
private onChange: () => void;

ngOnInit() {
this.validator = gt(this.gt);
}

ngOnChanges(changes: SimpleChanges) {
for (let key in changes) {
if (key === 'gt') {
this.validator = gt(changes[key].currentValue);
if (this.onChange) this.onChange();
}
}
}

validate(c: AbstractControl): {[key: string]: any} {
return this.validator(c);
}

registerOnValidatorChange(fn: () => void): void {
this.onChange = fn;
}
}
2 changes: 2 additions & 0 deletions src/greater-than-equal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './directive';
export * from './validator';
19 changes: 19 additions & 0 deletions src/greater-than-equal/validator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { FormControl } from '@angular/forms';

import { gt } from './';

describe('GT', () => {
const error = {gt: true};

it('5 should be gt 3', () => {
let control = new FormControl(5);

expect(gt(3)(control)).toBeNull();
});

it('3 should not be gt 5', () => {
let control = new FormControl(3);

expect(gt(5)(control)).toEqual(error);
});
});
13 changes: 13 additions & 0 deletions src/greater-than-equal/validator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { AbstractControl, Validators, ValidatorFn } from '@angular/forms';

import { isPresent } from '../util/lang';

export const gt = (gt: number): ValidatorFn => {
return (control: AbstractControl): {[key: string]: boolean} => {
if (!isPresent(gt)) return null;
if (isPresent(Validators.required(control))) return null;

let v: number = +control.value;
return v > +gt ? null : {gt: true};
};
};
2 changes: 1 addition & 1 deletion src/greater-than/validator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbstractControl, Validators, ValidatorFn } from '@angular/forms';

import { isPresent } from '../facade/lang';
import { isPresent } from '../util/lang';

export const gt = (gt: number): ValidatorFn => {
return (control: AbstractControl): {[key: string]: boolean} => {
Expand Down
2 changes: 1 addition & 1 deletion src/json/validator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbstractControl, Validators, ValidatorFn } from '@angular/forms';

import { isPresent } from '../facade/lang';
import { isPresent } from '../util/lang';

export const json: ValidatorFn = (control: AbstractControl): {[key: string]: boolean} => {
if (isPresent(Validators.required(control))) return null;
Expand Down
1 change: 1 addition & 0 deletions src/less-than-equal/directive.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// todo
Loading

0 comments on commit 0eaeb39

Please sign in to comment.