Validate name

sparkles
Tera Contributor

I have a single line text variable that allow user to enter name of the mailbox they want to create. We have stander format for the mailbox naming  (e.i. "MB - SS - name of the mailbox") How can I prevent user from submitting the request if the name doesn't have the  prefix?

Please help

Thanks

2 REPLIES 2

GlideFather
Tera Patron

Hi @sparkles,

 

Create a catalog client script (onSubmit) similar to this, I adjusted from my script using for long so you need to beautify and tweak it. It checks the email variable, gets the value in it and searching (indexOf) for the "MB" or "SS", i guess it must be changed (parsed the mailbox):

function onSubmit() {
  var mailboxName = g_form.getValue('mailbox_name'); // Replace with your variable name

 if ((mailboxName.indexOf('MB - ') === 0 || mailboxName.indexOf('SS - ') === 0)) {
    g_form.showFieldMsg('mailbox_name', 'Mail must contain "MB - " or "SS - ".', 'error');
    g_form.addErrorMessage('Please correct the mailbox name format.');
    return true; //Submi t ok
  }
  return false; // Submit notOk 
}

 

I have a question regarding the Mailbox, is it starting with "MB" and "SS" or containing? Because I don't think it is good to just check for a string in an email address... imagine "MillenniumBank" > "MB" or similar scenarios, unlikely but possible...

Wouldn't it be better to create a custom field on sys_user or sys_user_group and these users from the required mailbox would have that field populated, it could be a checkbox and the variable would call ajax for this true/false.

Let me know what do you think

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


Saturn
Tera Contributor

Hi @sparkles ,

 

You can create an onSubmit client script/catalog client script which will return false if the name entered doesn't starts with 'MB - SS -' . Please find below script.

 

robinprabha_0-1752962129879.png