import { Control } from "angular2/common" ; interface ValidationResult { [ key ] : boolean ; } export class UsernameValidator { static startsWithNumber ( control ) { if ( control . value != "" && ! isNaN ( control . value . charAt ( 0 ) ) ) { return { "startsWithNumber" : true } ; } return null ; } static usernameTaken ( control ) { return new Promise ( ( resolve , reject ) => { setTimeout ( ( ) => { if ( control . value === "David" ) { resolve ( { "usernameTaken" : true } ) ; } else { resolve ( null ) ; } ; } , 1000 ) ; } ) ; } }