blob: 55f60169d8e08f13ad5cf315bbf7fec82468f4e1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
export function getFieldError(field, minmax) {
if (field == null || field.length == 0) {
return "Required"
}
const [min, max] = minmax;
if (field.length < min) {
return "Too short";
}
if (field.length > max) {
return "Too long";
}
return null;
}
// Removes consecutive spaces.
export function cleanField(field) {
return field.replace(/\s{2,}/g, " ").replace(/\n{2,}/g, "\n");
}
export function correctFieldAnimate(field, setField, fieldErrors) {
if (fieldErrors == null) {
return;
}
setField({...field, animating: true, erroring: true});
}
// Requires lower case extension.
export function isSupportedExtension(ext) {
const extensions = ["png", "jpeg", "jpg"];
return extensions.some((e) => e == ext);
}
|