diff --git a/modules/angular2/src/common/forms/validators.ts b/modules/angular2/src/common/forms/validators.ts index f9cdc1c647..3cc476ca71 100644 --- a/modules/angular2/src/common/forms/validators.ts +++ b/modules/angular2/src/common/forms/validators.ts @@ -1,4 +1,4 @@ -import {isBlank, isPresent, CONST_EXPR} from 'angular2/src/facade/lang'; +import {isBlank, isPresent, CONST_EXPR, isString} from 'angular2/src/facade/lang'; import {PromiseWrapper} from 'angular2/src/facade/promise'; import {ObservableWrapper} from 'angular2/src/facade/async'; import {ListWrapper, StringMapWrapper} from 'angular2/src/facade/collection'; @@ -44,7 +44,9 @@ export class Validators { * Validator that requires controls to have a non-empty value. */ static required(control: modelModule.Control): {[key: string]: boolean} { - return isBlank(control.value) || control.value == "" ? {"required": true} : null; + return isBlank(control.value) || (isString(control.value) && control.value == "") ? + {"required": true} : + null; } /** diff --git a/modules/angular2/test/common/forms/validators_spec.ts b/modules/angular2/test/common/forms/validators_spec.ts index 5a1e13698c..2ce72b87aa 100644 --- a/modules/angular2/test/common/forms/validators_spec.ts +++ b/modules/angular2/test/common/forms/validators_spec.ts @@ -35,6 +35,9 @@ export function main() { it("should not error on a non-empty string", () => { expect(Validators.required(new Control("not empty"))).toEqual(null); }); + + it("should accept zero as valid", + () => { expect(Validators.required(new Control(0))).toEqual(null); }); }); describe("minLength", () => {