Hi @Aakash Goswami , yes you can do this. Please let me know if you have any questions and I can help you further.
You can configure custom error messages by modifying the onAttributeCollectionSubmit
response. This involves specifying the error message that should be displayed when the contact number validation fails. In your custom authentication extension, you can handle the validation logic and return a specific error message if the contact number does not match the Irish format.
You can use the onAttributeCollectionSubmit
method to validate the contact number. If the validation fails, you can set a custom error message. Here’s an example of how you can implement this:
onAttributeCollectionSubmit: function (context) {
var contactNumber = context.request.body.contactNumber;
var irishNumberPattern = /^(\+353|0)[1-9]\d{8}$/; // Example pattern for Irish numbers
if (!irishNumberPattern.test(contactNumber)) {
context.response.status = 400;
context.response.body = {
"error": {
"code": "InvalidContactNumber",
"message": "The contact number provided is not in the correct Irish format. Please enter a valid Irish contact number."
}
};
return context.done();
}
// Proceed with the normal flow if validation passes
context.done();
}
Check that your front-end application is configured to display the custom error message returned by the onAttributeCollectionSubmit
method. This might involve updating the form validation logic to handle and display the specific error message.
If modifying the onAttributeCollectionSubmit
response isn't feasible, you can consider using client-side validation to provide immediate feedback to the user before the form is submitted. This can be done using JavaScript to validate the contact number format and display a custom error message if the validation fails.
Please let me know if you have any questions and I can help you further.
If this answer helps you please mark "Accept Answer" so other users can reference it.
Thank you,
James