这是我的日期验证代码,将28/02/2017
填入输入类型文本并按下按钮。
首先,如果第一个警报为true
,警告true
警告true
,则会在代码中看到警告false
。但我的第二个是警惕if(regex.test(txt) === true)
{
alert("true");
p.innerHTML = "<h1 style='color:green'>Correct</h1>";
}
else
{
alert("false");
p.innerHTML = "<h1 style='color:red'>Wrong</h1>";;
}
。
检测布尔值
的错误是什么?<input type="text" id="date" name="date" value="dd/mm/yyyy" />
<button onclick="isDate();">Check</button>
<p id="response"></p>
<script>
function isDate() {
var regex = /^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/g;
var txt = document.getElementById("date").value;
var p = document.getElementById("response");
alert(regex.test(txt));
if(regex.test(txt) === true)
{
alert("true");
p.innerHTML = "<h1 style='color:green'>Correct</h1>";
}
else
{
alert("false");
p.innerHTML = "<h1 style='color:red'>Wrong</h1>";;
}
}
</script>
public class SomethingClient<T>
{
private readonly Func<T> somethingFactory;
public SomethingClient(Func<T> aSomethingFactory)
{
somethingFactory = aSomethingFactory;
}
public void SomeDynamicScenario()
{
var something = repositoryFactory();
//operate on new object
}
}