diff --git a/utils/string-utils.class.ts b/utils/string-utils.class.ts index e8b135ff..04a1a77b 100644 --- a/utils/string-utils.class.ts +++ b/utils/string-utils.class.ts @@ -1,4 +1,5 @@ import {UrlSegment} from '@angular/router'; +import {ValidatorFn, Validators} from "@angular/forms"; export class Dates { public static yearMin = 1800; @@ -215,6 +216,12 @@ export class StringUtils { return !!email.match("^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$"); } + public static urlValidator(): ValidatorFn { + return Validators.pattern('https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.' + + '[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.' + + '[a-zA-Z0-9]+\.[^\s]{2,}'); + } + public static sliceString(mystr, size: number): string { const sliced = String(mystr).substr(0, size); return sliced + (String(mystr).length > size ? '...' : '');