Need to add the serial number like CH1234,9Z5K3T3,4YLP9Y2,4YLP9Y5,.... separated with , and create

vinuth v
Tera Expert

Hi All,

 

I am working on one of the catalog form, in this form I have one field called "Serial Number" and it is multi line text.

Need to do the restriction like Serial number field should contains only serial number like 9Z5K3T3,CH1234... character and number.

 

Need to add the serial number like CH1234,9Z5K3T3,4YLP9Y2,4YLP9Y5,...... separated with , and I need to create a new asset record(new serial number) on the alm_hardware table.

 

Please any one suggest me how to do this one,

 

Thanks in advance,

Vinuth

 

1 REPLY 1

Shane J
Tera Guru

You'll need to setup a Catalog Client script that restrict the field OnChange via regex.

 

Here's a regex example that restricts based on a 21 character max:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
    if (isLoading || newValue == '') {
        return;
    }
    var regexp = /^(?!.*\s{2,})(?!^ )[^\d]{1,21}$/g;
    if (!regexp.test(newValue)) {
        alert('Enter a valid Name on card, 21 char or less.');
        g_form.setValue('str_name_on_card', '');
    }
   
}


Hit Google for Regex examples I suppose, but here's one...
https://medium.com/factory-mind/regex-tutorial-a-simple-cheatsheet-by-examples-649dc1c3f285