From 5f90435442f703b248a9946ba522f2328eca3e27 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Mon, 13 May 2024 16:09:14 +0300 Subject: [PATCH] National ID input validation added --- lib/pages/login/login.dart | 32 +++++++++++++++++--------------- lib/uitl/utils.dart | 3 ++- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/pages/login/login.dart b/lib/pages/login/login.dart index d55c4017..bf32c40f 100644 --- a/lib/pages/login/login.dart +++ b/lib/pages/login/login.dart @@ -126,11 +126,13 @@ class _Login extends State { ), DefaultButton( TranslationBase.of(context).login, - isButtonDisabled - ? null - : () { - this.startLogin(); - }, + () { + if (isButtonDisabled) { + AppToast.showErrorToast(message: "National ID can only contain numbers"); + } else { + this.startLogin(); + } + }, disabledColor: Color(0xff575757), ), ]), @@ -227,7 +229,7 @@ class _Login extends State { } void validateForm() { - if (util.validateIDBox(nationalIDorFile.text, loginType) == true && util.isSAUDIIDValid(nationalIDorFile.text, loginType) == true) { + if (util.validateIDBox(nationalIDorFile.text, loginType) == true && (countryCode == "971" ? true : util.isSAUDIIDValid(nationalIDorFile.text, loginType) == true)) { setState(() { isButtonDisabled = false; }); @@ -257,16 +259,16 @@ class _Login extends State { GifLoaderDialogUtils.showMyDialog(context); authService.checkPatientAuthentication(request).then((value) { // if (value['UserAccountIsActivated']) { - if (value['isSMSSent']) { - sharedPref.setString(LOGIN_TOKEN_ID, value['LogInTokenID']); - sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, request); - GifLoaderDialogUtils.hideDialog(context); - Navigator.of(context).push(FadePage(page: ConfirmLogin())); - } else { - if (value['IsAuthenticated']) { - this.checkActivationCode(); - } + if (value['isSMSSent']) { + sharedPref.setString(LOGIN_TOKEN_ID, value['LogInTokenID']); + sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, request); + GifLoaderDialogUtils.hideDialog(context); + Navigator.of(context).push(FadePage(page: ConfirmLogin())); + } else { + if (value['IsAuthenticated']) { + this.checkActivationCode(); } + } // } else { // ConfirmDialog activationDialog = new ConfirmDialog( // context: context, diff --git a/lib/uitl/utils.dart b/lib/uitl/utils.dart index a77579e2..960ae8a2 100644 --- a/lib/uitl/utils.dart +++ b/lib/uitl/utils.dart @@ -166,12 +166,13 @@ class Utils { Pattern pattern = loginIDPattern(type); //r'^\d+(?:\.\d+)?$'; RegExp regex = new RegExp(pattern); + print(regex.hasMatch(value)); return regex.hasMatch(value); } String loginIDPattern(loginType) { var length = loginType == 1 ? 10 : 1; - return "([0-9]{" + length.toString() + "})"; + return "([0-9]{" + length.toString() + "}\$)"; } static showProgressDialog(context, [String message = "Loading..."]) async {