Fix validator for company editor

This commit is contained in:
2025-08-30 08:31:35 -07:00
parent 3c8a083368
commit 9ee739622c
4 changed files with 30 additions and 12 deletions
@@ -109,3 +109,13 @@ form {
height: 40px;
break-inside: avoid;
}
.error-window {
position: absolute;
left: calc(50% - 400px);
width: 800px;
text-align: center;
top: 600px;
background-color: red;
border-radius: 10px;
}
@@ -168,3 +168,9 @@
</div>
</div>
</form>
@if (ErrorMsg != ""){
<div class="error-window">
<h1>{{ ErrorMsg }}</h1>
</div>
}
@@ -149,9 +149,10 @@ export class CompanyEditorComponent {
return;
}
if (this.validator.validateURL(company.websiteURL)[0]){
this.ErrorMsg = "Website is invalid";
this.focusFrame(3, 1);
var urlIsValid = this.validator.validateURL(company.websiteURL);
if (urlIsValid[0] == false){
this.ErrorMsg = urlIsValid[1];
this.focusFrame(1, 0);
return;
}
@@ -167,8 +168,9 @@ export class CompanyEditorComponent {
return;
}
if (this.validator.validateEmail(company.email)[0]){
this.ErrorMsg = "Email is invalid";
var emailIsValid = this.validator.validateEmail(company.email);
if (emailIsValid[0] == false){
this.ErrorMsg = emailIsValid[1];
this.focusFrame(3, 0);
return;
}
@@ -179,7 +181,7 @@ export class CompanyEditorComponent {
return;
}
if (this.validator.validatePhoneNumber(company.phone)[0]){
if (this.validator.validatePhoneNumber(company.phone)[0] == false){
this.ErrorMsg = "Phone number is invalid";
this.focusFrame(3, 1);
return;
+5 -5
View File
@@ -46,28 +46,28 @@ export class Validation {
try {
if (urlToParse.protocol !== 'http:' && urlToParse.protocol !== 'https:') {
return [false, urlToParse.href];
return [false, "bad protocol"];
}
const hostname = urlToParse.hostname.toLowerCase();
if (hostname === 'localhost' || hostname.endsWith('.localhost')) {
return [false, urlToParse.href];
return [false, "localhost not allowed"];
}
const privateIpRegex = /^(127\.|10\.|192\.168\.|172\.(1[6-9]|2[0-9]|3[0-1])\.)/;
if (privateIpRegex.test(hostname)) {
return [false, urlToParse.href];
return [false, "internal ipv4 not allowed"];
}
if (hostname.includes(':')) {
if (this.isPrivateIPv6(hostname)) {
return [false, urlToParse.href];
return [false, "internal ipv6 not allowed"];
}
}
return [true, urlToParse.href.substring(0, urlToParse.href.length - 1)];
} catch (e) {
return [false, urlToParse.href];
return [false, "validation error has occurred"];
}
}