Skip to content

Commit 9341346

Browse files
chouchoujichouchouji
andauthored
docs: add type assert for text validation example (#389)
Co-authored-by: chouchouji <jibinbin@dcloud.io>
1 parent 2839c66 commit 9341346

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

examples/basic/text-validation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ async function main() {
99
message: 'Enter your name (letters and spaces only)',
1010
initialValue: 'John123', // Invalid initial value with numbers
1111
validate: (value) => {
12-
if (!/^[a-zA-Z\s]+$/.test(value)) return 'Name can only contain letters and spaces';
12+
if (!value || !/^[a-zA-Z\s]+$/.test(value)) return 'Name can only contain letters and spaces';
1313
return undefined;
1414
},
1515
});
@@ -25,7 +25,7 @@ async function main() {
2525
message: 'Enter another name (letters and spaces only)',
2626
initialValue: 'John Doe', // Valid initial value
2727
validate: (value) => {
28-
if (!/^[a-zA-Z\s]+$/.test(value)) return 'Name can only contain letters and spaces';
28+
if (!value || !/^[a-zA-Z\s]+$/.test(value)) return 'Name can only contain letters and spaces';
2929
return undefined;
3030
},
3131
});

0 commit comments

Comments
 (0)