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