diff --git a/mobile/lib/modules/login/ui/login_form.dart b/mobile/lib/modules/login/ui/login_form.dart index c485ce4ae9..0a0e84ea9a 100644 --- a/mobile/lib/modules/login/ui/login_form.dart +++ b/mobile/lib/modules/login/ui/login_form.dart @@ -96,12 +96,20 @@ class ServerEndpointInput extends StatelessWidget { const ServerEndpointInput({Key? key, required this.controller}) : super(key: key); + String? _validateInput(String? url) { + if (url == null) return null; + if (!url.startsWith(RegExp(r'https?://'))) return 'Please specify http:// or https://'; + return null; + } + @override Widget build(BuildContext context) { return TextFormField( controller: controller, decoration: const InputDecoration( labelText: 'Server Endpoint URL', border: OutlineInputBorder(), hintText: 'http://your-server-ip:port'), + validator: _validateInput, + autovalidateMode: AutovalidateMode.always, ); } } @@ -111,12 +119,22 @@ class EmailInput extends StatelessWidget { const EmailInput({Key? key, required this.controller}) : super(key: key); + String? _validateInput(String? email) { + if (email == null || email == '') return null; + if (email.endsWith(' ')) return 'Trailing whitespace'; + if (email.startsWith(' ')) return 'Leading whitespace'; + if (email.contains(' ') || !email.contains('@')) return 'Invalid Email'; + return null; + } + @override Widget build(BuildContext context) { return TextFormField( controller: controller, decoration: const InputDecoration(labelText: 'Email', border: OutlineInputBorder(), hintText: 'youremail@email.com'), + validator: _validateInput, + autovalidateMode: AutovalidateMode.always, ); } }