feat: implement edit userinfo

This commit is contained in:
Steven
2023-06-23 20:52:00 +08:00
parent 9ad2eaebc5
commit 9b303da4eb
11 changed files with 173 additions and 189 deletions

View File

@@ -1,52 +0,0 @@
// Validator
// * use for validating form data
const chineseReg = /[\u3000\u3400-\u4DBF\u4E00-\u9FFF]/;
export interface ValidatorConfig {
// min length
minLength: number;
// max length
maxLength: number;
// no space
noSpace: boolean;
// no chinese
noChinese: boolean;
}
export function validate(text: string, config: Partial<ValidatorConfig>): { result: boolean; reason?: string } {
if (config.minLength !== undefined) {
if (text.length < config.minLength) {
return {
result: false,
reason: "Too short",
};
}
}
if (config.maxLength !== undefined) {
if (text.length > config.maxLength) {
return {
result: false,
reason: "Too long",
};
}
}
if (config.noSpace && text.includes(" ")) {
return {
result: false,
reason: "Don't allow space",
};
}
if (config.noChinese && chineseReg.test(text)) {
return {
result: false,
reason: "Don't allow chinese",
};
}
return {
result: true,
};
}