how to write a script for only alphabet letters using ServiceNow

Ashok M
Tera Contributor

The employee name should contain only alphabets and space and not more than 30 characters on the whole.
7 REPLIES 7

Raghu Ram Y
Kilo Sage

@Ashok M 

1. Field should accept only string.

Create onChange Client Script on that particular field.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var field = g_form.getValue('fieldname');
    if (!field.match(/^[A-Za-z ]*$/)) {
        alert('Please enter only text');
        g_form.clearValue('fieldname');
        return false;
    }
}

 

2. Limit length to 30 Characters.

Right Click on the field and click on Configure Dictionary and set max length to 30 like below screenshot.

find_real_file.png 

@Ashok M have you checked my suggestion? I hope it helps, if so please mark my response as correct and helpful.

Ashok M
Tera Contributor

Thanks Raghu

 

Hi, Can you please mark my response as HELPFUL and CORRECT, if it helps you