aboutsummaryrefslogtreecommitdiff
path: root/src/web/helpers/Input.jsx
diff options
context:
space:
mode:
authorNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-13 18:04:18 +1100
committerNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-13 18:04:18 +1100
commit93dfe2be64e8658839bcfe5356adf35f8cde7075 (patch)
treec60b1e20d569b74dbde85123e1b2bf3590c66244 /src/web/helpers/Input.jsx
initial commit
Diffstat (limited to 'src/web/helpers/Input.jsx')
-rw-r--r--src/web/helpers/Input.jsx31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/web/helpers/Input.jsx b/src/web/helpers/Input.jsx
new file mode 100644
index 0000000..55f6016
--- /dev/null
+++ b/src/web/helpers/Input.jsx
@@ -0,0 +1,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);
+} \ No newline at end of file