Search code examples
javascriptservicenow

Javascript var case sensitive


Firstly I will start with a disclaimer. I am new to javascript.

This javascript is for ServiceNow. It is to stop certain staff members from raising a catalog item. It is working, however if a user was to use a capital, it would allow it.

I would like to make the script case insensitive.

I use a variable to define the email address:

var deny = "@email.com.au";

and then the variable is used in an if statement.

if (email.indexOf(deny) >= 0){
            g_form.showFieldMsg('variable', "email.com.au is not accepted" , 'error');
            g_form.setValue('variable',"");

How does one do this?

Cheers


Solution

  • You can convert email to lowerCase and check index

    if(email.toLowerCase().indexOf(deny) >= 0){
            g_form.showFieldMsg('variable', "email.com.au is not accepted" , 'error');
            g_form.setValue('variable',"");