@@ -98,6 +98,16 @@ fun Toast.successToast(message: String, activity: Activity) {
9898 }
9999}
100100
101+ /* *
102+ Checks if a password is valid based on the following criteria:
103+ Contains at least one uppercase letter
104+ Contains at least one lowercase letter
105+ Contains at least one digit
106+ Contains at least one special character from the set [!@#$&*~]
107+ Has a minimum length of 8 characters
108+ @param password The password to be validated.
109+ @return true if the password is valid, false otherwise.
110+ */
101111fun isValidPassword (password : String ): Boolean {
102112 val pattern: Pattern
103113 val PASSWORD_PATTERN = " ^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#\\ \$ &*~]).{8,}\$ "
@@ -106,11 +116,21 @@ fun isValidPassword(password: String): Boolean {
106116 return matcher.matches()
107117}
108118
119+ /* *
120+ Checks if an email address is valid.
121+ @param email The email address to be validated.
122+ @return true if the email address is valid, false otherwise.
123+ */
109124fun isValidEmail (email : String ): Boolean {
110125 val pattern = Patterns .EMAIL_ADDRESS
111126 return pattern.matcher(email).matches()
112127}
113128
129+ /* *
130+ Validates an email address and returns the validation status.
131+ @param email The email address to be validated.
132+ @return The ValidationStatus enum indicating the validation status of the email.
133+ */
114134fun validateEmail (email : String? ): ValidationStatus {
115135 return when {
116136 email.isNullOrEmpty() -> ValidationStatus .EMPTY_EMAIL
@@ -119,6 +139,11 @@ fun validateEmail(email: String?): ValidationStatus {
119139 }
120140}
121141
142+ /* *
143+ Validates a password and returns the validation status.
144+ @param password The password to be validated.
145+ @return The ValidationStatus enum indicating the validation status of the password.
146+ */
122147fun validatePassword (password : String? ): ValidationStatus {
123148 return when {
124149 password.isNullOrEmpty() -> ValidationStatus .EMPTY_PASSWORD
@@ -127,48 +152,84 @@ fun validatePassword(password: String?): ValidationStatus {
127152 }
128153}
129154
155+ /* *
156+ Validates a first name and returns the validation status.
157+ @param v The first name to be validated.
158+ @return The ValidationStatus enum indicating the validation status of the first name.
159+ */
130160fun validFirstName (v : String? ): ValidationStatus {
131161 return when {
132162 v.isNullOrEmpty() -> ValidationStatus .EMPTY_FIRSTNAME
133163 else -> ValidationStatus .VALID
134164 }
135165}
136166
167+ /* *
168+ Validates a last name and returns the validation status.
169+ @param v The last name to be validated.
170+ @return The ValidationStatus enum indicating the validation status of the last name.
171+ */
137172fun validLastName (v : String? ): ValidationStatus {
138173 return when {
139174 v.isNullOrEmpty() -> ValidationStatus .EMPTY_LASTNAME
140175 else -> ValidationStatus .VALID
141176 }
142177}
143178
179+ /* *
180+ Validates a username and returns the validation status.
181+ @param v The username to be validated.
182+ @return The ValidationStatus enum indicating the validation status of the username.
183+ */
144184fun validUsername (v : String? ): ValidationStatus {
145185 return when {
146186 v.isNullOrEmpty() -> ValidationStatus .EMPTY_USERNAME
147187 else -> ValidationStatus .VALID
148188 }
149189}
150190
191+ /* *
192+ Validates a home address and returns the validation status.
193+ @param v The home address to be validated.
194+ @return The ValidationStatus enum indicating the validation status of the home address.
195+ */
151196fun validHomeAddress (v : String? ): ValidationStatus {
152197 return when {
153198 v.isNullOrEmpty() -> ValidationStatus .EMPTY_USERNAME
154199 else -> ValidationStatus .VALID
155200 }
156201}
157202
203+ /* *
204+ Validates an office address and returns the validation status.
205+ @param v The office address to be validated.
206+ @return The ValidationStatus enum indicating the validation status of the office address.
207+ */
158208fun validOfficeAddress (v : String? ): ValidationStatus {
159209 return when {
160210 v.isNullOrEmpty() -> ValidationStatus .EMPTY_USERNAME
161211 else -> ValidationStatus .VALID
162212 }
163213}
164214
215+ /* *
216+ Validates a mobile number and returns the validation status.
217+ @param v The mobile number to be validated.
218+ @return The ValidationStatus enum indicating the validation status of the mobile number.
219+ */
165220fun validMobile (v : String? ): ValidationStatus {
166221 return when {
167222 v.isNullOrEmpty() -> ValidationStatus .EMPTY_MOBILENO
168223 else -> ValidationStatus .VALID
169224 }
170225}
171226
227+ /* *
228+ Validates the confirm password and returns the validation status.
229+ @param password The password entered by the user.
230+ @param confirmPassword The confirm password entered by the user.
231+ @return The ValidationStatus enum indicating the validation status of the confirm password.
232+ */
172233fun validConfirmPassword (password : String? , confirmPassword : String? ): ValidationStatus {
173234 // validate confirm password
174235 if (TextUtils .isEmpty(confirmPassword)) {
@@ -180,12 +241,21 @@ fun validConfirmPassword(password: String?, confirmPassword: String?): Validatio
180241 return ValidationStatus .VALID
181242}
182243
244+ /* *
245+ Retrieves the error message for a specific ValidationStatus.
246+ @param context The context used to retrieve the string resources.
247+ @return The error message corresponding to the ValidationStatus.
248+ */
183249fun ValidationStatus.getErrorMessage (context : Context ): String? {
184250 val errorMessageResId = ValidationConstants .validationStatusErrorMap[this ]
185251 return errorMessageResId?.let { context.getString(it) }
186252}
187253
188- // Function to hide the keyboard
254+ /* *
255+ Hides the keyboard.
256+ @param context The context used to retrieve the input method manager.
257+ @param view The view from which to retrieve the window token.
258+ */
189259fun hideKeyboard (context : Context , view : View ) {
190260 val inputMethodManager =
191261 context.getSystemService(Context .INPUT_METHOD_SERVICE ) as InputMethodManager
0 commit comments