Mask variable with Regex Validation

Chris Foreman
Tera Contributor

I recently created a new Catalog Item with two fields that require the user to enter PIN codes.  Each has a separate Regex validation applied to it, one for 4 digits and the other for 6 digits.

 

Once the item was in production, we realized that we were leaving Alarm codes plain text available to anyone with ITIL access and the ability to find them.  I attempted to change one of them to a Mask variable and that seemed to fix the security issue but now I cannot apply my validation so the user can type as many characters as they like.

 

Is it possible to use a mask variable with Regex validation?

 

Thanks

1 ACCEPTED SOLUTION

Muhammad Khan
Mega Sage

Try creating onSubmit() client script on your catalog item and utilize below script.

 

function onSubmit() {
    var test = g_form.getValue('backend_name_of_variable');
    var regex = /^\d{3}$/;

    if (!test.match(regex)) {
        g_form.showFieldMsg('backend_name_of_variable', 'Invalid Password', 'error', true);
        return false;
    }
}

 

View solution in original post

4 REPLIES 4

Muhammad Khan
Mega Sage

Try creating onSubmit() client script on your catalog item and utilize below script.

 

function onSubmit() {
    var test = g_form.getValue('backend_name_of_variable');
    var regex = /^\d{3}$/;

    if (!test.match(regex)) {
        g_form.showFieldMsg('backend_name_of_variable', 'Invalid Password', 'error', true);
        return false;
    }
}

 

Thank you for the suggestion.  I will give it shot in my Dev environment.

This works and I marked it as the solution.  I do have one issue.  Sometimes the box can be empty and I am struggling with adding a check for null/undefined.

Add test!='' along with the previous condition in if statement. Below script might help.

function onSubmit() {
    var test = g_form.getValue('backend_name_of_variable');
    var regex = /^\d{3}$/;

    if (test!='' && !test.match(regex)) {
        g_form.showFieldMsg('backend_name_of_variable', 'Invalid Password', 'error', true);
        return false;
    }
}