Add app source and tests
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
26
lib/Peach/utils/Validators.dart
Normal file
26
lib/Peach/utils/Validators.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
// Form validators. Screens reference these rather than writing closures
|
||||
// inline, so an error message reads the same wherever the rule applies.
|
||||
|
||||
String? requiredField(String? value) =>
|
||||
(value == null || value.trim().isEmpty) ? 'Required' : null;
|
||||
|
||||
String? validPort(String? value) {
|
||||
if (value == null || value.trim().isEmpty) return null; // falls back to 22
|
||||
final port = int.tryParse(value.trim());
|
||||
if (port == null) return 'Numbers only';
|
||||
if (port < 1 || port > 65535) return 'Must be 1–65535';
|
||||
return null;
|
||||
}
|
||||
|
||||
String? validHost(String? value) {
|
||||
if (value == null || value.trim().isEmpty) return 'Required';
|
||||
if (value.trim().contains(' ')) return 'No spaces allowed';
|
||||
return null;
|
||||
}
|
||||
|
||||
/// An absolute POSIX path, as every remote target must be.
|
||||
String? validRemotePath(String? value) {
|
||||
if (value == null || value.trim().isEmpty) return 'Required';
|
||||
if (!value.trim().startsWith('/')) return 'Must start with /';
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user