【发布时间】:2016-11-30 01:14:38
【问题描述】:
这段代码想要检查一个数组中是否有名字,并且数组中所有名字的第一个字母都是大写的。很多用户在写自己的名字时没有在名字中使用大写字母。
所以我想通过正则表达式( /i )在代码中传递这个条件,我可以将它与字符串和其他一些函数一起使用,但我不能将它与变量一起使用。
谁能帮帮我?
function runTest() {
"use strict";
var value = document.getElementById("inin").value;
if (names.indexOf(value) > -1) {
x.innerHTML = "yes " + value + " your name is here, your are fully approved";
} else {
x.innerHTML = "Sorry, Your name isn't here";
}
}
【问题讨论】:
-
确保您的列表全部为小写或大写,并将传入的值转换为该大小写。
标签: javascript regex variables indexof