Skip to content

Instantly share code, notes, and snippets.

@wspringer
Last active February 3, 2019 22:29
Show Gist options
  • Save wspringer/df828e5e25aa3b008e817726cccf6127 to your computer and use it in GitHub Desktop.
Save wspringer/df828e5e25aa3b008e817726cccf6127 to your computer and use it in GitHub Desktop.
let numberRegexp = /^[0-9]+$/;
export interface Validator<T> {
isAcceptable(t: T): boolean;
}
export class ZipCodeValidator implements Validator<String> {
isAcceptable(s: string) {
return s.length === 5 && numberRegexp.test(s);
}
}
(new ZipCodeValidator()).isAcceptable("09800"); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment