How to Create Auto Formatting Phone Number in Accounts

Hi everbody,

I need some help. I want to create auto phone number formatting.
I entering this format at first --> 902161111111
Then I want it to be converted to this format after saving–> +90(216) 111 1111

I try logichooks. But I failed.Please help me.

Thank you.

Hi,
You can use login hook. This is the best option. You should use BEFORE_SAVE logic hook.
How did you used the hooks??

Other Option can be to use JavaScript at front end, and run in ON BLUR event of the field.
For both of the things, you will need coding skills.

Thanks

Hi Elite,

I used before_save but they didn’t work. Or I couldn’t.

Firstly custom\modules\Accounts\logic_hooks.php --> $hook_array[‘before_save’][] = Array(1, ‘tutorialNumber’, ‘custom/modules/Accounts/tutorial_number.php’, ‘tutorial_number’, ‘number’);

Then I added custom\modules\Accounts\tutorial_number.php and I filled in these codes ;

class tutorial_number
{

  function number ($bean, $event, $arguments)
  {
	  
	  $bean = '092163688776';
	  $event = '/([0-9]{12})';
	  $arguments = '/([\+]90?)([ ]?)(\([0-9]{3}\))([ ]?)([0-9]{3})(\s*[\-]?)([0-9]{2})(\s*[\-]?)([0-9]{2})';
	  
	  echo preg_replace($event, $arguments, $bean);
	  
  }

}

I’m sure some parts are wrong. Maybe you can help me coding things.

Thanks.

Hi,
Many things are wrong here.

Code is not valid and also Logic Hook definition is also not valid.

Can you Skype please? This will save the time.

Hi,

Is there a platform to communicate with? I do not use Skype.

Thanks

1 Like

I need this code also. Do you share it with me?
Thanks.

I also need something like this…can you explain what is wrong with the code above?

Thanks!

hi,
the code should assign the value to $bean instead it is displaying the values

We can create an entry point and make an Ajax call to the entry point on the event of onchange or onblur and set the control value with response received from the entry point in javascript code.

Could you please provide step-by-step guidance on it?

Logics hook will be the good approach, you can check this example if using logic hooks

Logic Hooks :: SuiteCRM Documentation

How to update a field in an after_save logic hook? - Dev Answers & Best Practices - DevClub - SugarClub (sugarcrm.com)