Create contact - email address validation does not allow apostrophe

Hi, I’m very new to developing with SuiteCRM8 (v8.7.1) and I’m having an issue with some front end validation. I can’t work out where to change it.

In the Contact module, when creating a new contact, the email field validation does not allow apostrophes. This is an issue as this should be a valid character in an email address.

I can’t for the life of me find where to change the validation rules?

The sort of thing is configured here

Here is the guide on how to override config values safely if you’ve not seen it already

2 Likes

Hi Matt, thanks for the reply.

I’ve followed the instructions on the video to create an override for that UI config. Php looks as follows (the regex now allows the apostrophe on the left side):

<?php

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\DependencyInjection\ContainerBuilder;

return static function (ContainerBuilder $container): void {

$ui = $container->getParameter('ui') ?? [];
$ui['regex']['validations'] = [
    'email' => '^(?:[\.\-\+&#!\$\*=\?\^_`\{\}~\/\w\']+)@(?:(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|\w+(?:[\.-]*\w+)*(?:\.[\w-]{2,})+)$'
];

$container->setParameter('ui', $ui);

};

This file is located at extensions/defaultExt/config/services/ui/ui.php

However, even after a repair & rebuild and running cache:clear via console it hasn’t made any difference at all to that email field on the create Contact form, it’s still using the old validation.

As a test I made the regex change directly to the YAML file in config/services/ui/ui.yaml and this DID work. So for some reason my override isn’t getting applied, any idea why?

Thanks

We can copy the file from config/services/ui/ui.yaml at extensions/defaultExt/config/services/ui/ui.yaml and make the regex change. This should work.

1 Like

Thanks Harshad, this worked.

I would like to know why the suggested way in Matt’s reply doesn’t work, but this solution is good enough for now.

This looks like it’s the wrong way around needs to be the same structure as in the core file

$ui['validations']['regex']['email'] = 

Overriding the whole file will likely lead to issues when upgrading to future releases, so this is not a recommended approach

2 Likes

I’m sure I double checked the fields :man_facepalming:

Correcting the order has resolved this. I’ve marked your original answer as the solution. Thanks again.

1 Like