'How to customize Sign Up/In validation messages in AWS Cognito Hosted UI

I am using AWS Cognito Hosted UI for authentication purposes in my project. In case of some validation error, it shows very technical error messages. For example, in case of a blank space in the username at the time of login, it shows the following error message:

2 validation errors detected: Value at 'userAlias' failed to satisfy constraint: Member must satisfy regular expression pattern: [\p{L}\p{M}\p{S}\p{N}\p{P}]+; Value at 'userName' failed to satisfy constraint: Member must satisfy regular expression pattern: [\p{L}\p{M}\p{S}\p{N}\p{P}]+

I tried returning a user-friendly error message by writing a Lambda function on the PreAuthentication trigger. But the validation process takes place before calling the Lambda function itself. Is there any way to translate/customize these validation messages?

EDIT: Various forums suggest the following link but I am not able to find any clue. https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pool-managing-errors.html



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source