简体   繁体   中英

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

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',"");

尝试将javascript函数转换为小写 ,然后执行indexof

Take the email array and convert all the content to lowercase using

for (int i = 0;i < email.length;i++) {
    email[i] = email[i].toLowerCase();
}

Then Compare

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM