39 lines
742 B
JavaScript
39 lines
742 B
JavaScript
import { Field } from "./Field.js";
|
|
import { ValidationError } from "../ValidationError.js";
|
|
|
|
export class DmarcUriListField extends Field {
|
|
separator = "=";
|
|
|
|
constructor(key) {
|
|
super(key);
|
|
}
|
|
|
|
validate(value) {
|
|
const uris = value.split(",");
|
|
|
|
for (let uri of uris) {
|
|
uri = uri.replace(/!\d+[kmgt]?$/);
|
|
|
|
try {
|
|
new URL(uri);
|
|
} catch(e) {
|
|
throw new ValidationError(`Invalid URI for field "${this.key}": ${uri}`);
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
getInputHtml() {
|
|
return `<input id="${this.id}" type="email" name="${this.key}" placeholder="mail@example.com">`;
|
|
}
|
|
|
|
getInputValue() {
|
|
if (!document.getElementById(this.id).value) {
|
|
return null;
|
|
}
|
|
|
|
return "mailto:" + document.getElementById(this.id).value;
|
|
}
|
|
}
|