The following format for the field is to be accepted

Not applicable

Hi,

I have a requirement where the following format is only accepted for a field. Kindly help.

rocisw01nfs.unix.rabk.com:/appshares/san

Regards

Suman P.

1 ACCEPTED SOLUTION

@Community Alums Please update your script as follows.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var re = /^[a-z0-9]+.[a-z]+.[a-z]+.[a-z]+:\/[a-z]+\/[a-z]+$/;
    if (!re.test(g_form.getValue('nfs_export')) {		
        g_form.addErrorMessage('Invalid format for NFS Export');
		g_form.clearValue('nfs_export');
        return false;
    }

}

Hope this helps.

View solution in original post

10 REPLIES 10

vermaamit16
Kilo Patron

Hi @Community Alums 

 

You need to create a regex for this first. You can try with below regex :

 

([A-Za-z0-9]+(\.[A-Za-z0-9]+)+):/[A-Za-z]+/[A-Za-z]+

 

You can generate the regex from the below link :

https://regex-generator.olafneumann.org/?sampleText=rocisw01nfs.unix.rabk.com%3A%2Fappshares%2Fsan&flags=i&selection=0%7CCombination%20%5BAlphanumeric%20characters%20%2B%20Character%5D,25%7CCharacter,26%7CCharacter,27%7CMultiple%20characters,36%7CCharacter,37%7CMultiple%20characters

 

Once done, please follow below post to use it :

https://www.servicenow.com/community/developer-articles/field-validation-regular-expressions/ta-p/2321095

 

Thanks & Regards

Amit Verma

Thanks and Regards
Amit Verma

Not applicable
/([A-Za-z0-9]+(\.[A-Za-z0-9]+)+):\/[A-Za-z]+\/[A-Za-z]+/i;

@Community Alums 

 

Is your query addressed ? If yes, can you please mark my answer as correct for others to follow.

Thanks and Regards
Amit Verma

Not applicable

 Hi @vermaamit16 @Sandeep Rajput ,

I tried both of your suggestions. Thank you, but it is not working. Please correct me.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var re = /^[a-z0-9]+.[a-z]+.[a-z]+.[a-z]+:\/[a-z]+\/[a-z]+$/;
    if (!re.test("nfs_export")) {		
        g_form.addErrorMessage('Invalid format for NFS Export');
		g_form.clearValue('nfs_export');
        return false;
    }

}

 

It just clears off the value once i enter abc.unix.rgbk.com:/appshares/san

 

Regards

Suman P.

@Community Alums Please update your script as follows.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var re = /^[a-z0-9]+.[a-z]+.[a-z]+.[a-z]+:\/[a-z]+\/[a-z]+$/;
    if (!re.test(g_form.getValue('nfs_export')) {		
        g_form.addErrorMessage('Invalid format for NFS Export');
		g_form.clearValue('nfs_export');
        return false;
    }

}

Hope this helps.