[英]Javascript var case sensitive
Firstly I will start with a disclaimer. 首先,我将从免责声明开始。 I am new to javascript. 我是javascript新手。
This javascript is for ServiceNow. 此javascript用于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语句中使用该变量。
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 然后比较
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.