From: Chocobozzz Date: Sun, 27 Nov 2016 16:45:00 +0000 (+0100) Subject: Client: improve host regex X-Git-Tag: v0.0.1-alpha~590 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=447fde277497dfff73310dc12bf79fb576139b94;p=oweals%2Fpeertube.git Client: improve host regex --- diff --git a/client/src/app/admin/friends/friend-add/friend-add.component.ts b/client/src/app/admin/friends/friend-add/friend-add.component.ts index 22b0241b4..014252011 100644 --- a/client/src/app/admin/friends/friend-add/friend-add.component.ts +++ b/client/src/app/admin/friends/friend-add/friend-add.component.ts @@ -83,13 +83,8 @@ export class FriendAddComponent implements OnInit { this.friendService.makeFriends(notEmptyHosts).subscribe( status => { - // TODO: extractdatastatus - // if (status === 409) { - // alert('Already made friends!'); - // } else { - alert('Make friends request sent!'); - this.router.navigate([ '/admin/friends/list' ]); - // } + alert('Make friends request sent!'); + this.router.navigate([ '/admin/friends/list' ]); }, error => alert(error.text) ); diff --git a/client/src/app/shared/forms/form-validators/host.validator.ts b/client/src/app/shared/forms/form-validators/host.validator.ts index 9cb46d361..ea3e43cb1 100644 --- a/client/src/app/shared/forms/form-validators/host.validator.ts +++ b/client/src/app/shared/forms/form-validators/host.validator.ts @@ -1,7 +1,10 @@ import { FormControl } from '@angular/forms'; export function validateHost(c: FormControl) { - let HOST_REGEXP = new RegExp('^(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$'); + // Thanks to http://stackoverflow.com/a/106223 + let HOST_REGEXP = new RegExp( + '^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$' + ); return HOST_REGEXP.test(c.value) ? null : { validateHost: {