25 lines
447 B
JavaScript
25 lines
447 B
JavaScript
import { Field } from "./Field.js";
|
|
import { ValidationError } from "../ValidationError.js";
|
|
|
|
export class DmarcUriListField extends Field {
|
|
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;
|
|
}
|
|
}
|