Page MenuHomeSealhub

phone-number.ts
No OneTemporary

phone-number.ts

import { Context } from "koa";
import { FormControl, SimpleInput } from "../controls/controls.js";
import { FormDataValue } from "../form-types.js";
import { FormField } from "./field.js";
export class PhoneNumberWithoutCountryCode<
Required extends boolean,
> extends FormField<Required, string> {
public getEmptyValue(): string {
return "000 000 000";
}
async parse(ctx: Context, raw_value: FormDataValue) {
if (typeof raw_value == "string") {
return {
parsable: <const>true,
parsed_value: raw_value
.replaceAll(/[^0-9]/, "")
.replace(/(\d{3})(?=\d)/g, "$1 ")
.trim(),
error: null,
};
} else {
return {
parsable: <const>false,
parsed_value: null,
error: "Expected string",
};
}
}
getControl(): FormControl {
return new SimpleInput(this, {
inputmode: "tel",
type: "text",
placeholder: "123 456 789",
});
}
}

File Metadata

Mime Type
text/x-java
Expires
Sun, Nov 2, 17:30 (14 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1029272
Default Alt Text
phone-number.ts (891 B)

Event Timeline