Client: improve host regex

This commit is contained in:
Chocobozzz 2016-11-27 17:45:00 +01:00
parent 437cf8b531
commit 447fde2774
2 changed files with 6 additions and 8 deletions

View File

@ -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)
);

View File

@ -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: {