我正在用JavaScript寫一個生日驗證表單,但它不起作用。你能幫忙找出哪一部分是錯的嗎?如何解決它?日期驗證JavaScript
的JavaScript
function onFormSubmit(form_element) {
var slashcount = 0;
if ((form_element.birthday.value =="")||(form_element.birthday.value ==null))
{
alert("This field is required. Please enter date mm/dd/yyyy!");
false;
}
for (var i=0; i < birthday.length; i++)
{
temp = "" + birthday.substring(i, i+1);
if (temp == "/")
{
slashcount++;
}
if (valid.indexOf(temp) == "-1")
{
alert("error1.");
false;
}
if (slashcount != 2)
{
alert("error2");
false;
}
if((birthday.charAt(2)!= '/')||(birthday.charAt(5) != '/'))
{
alert("error3");
false;
}
}
return true;
}
HTML
<form onsubmit="return onFormSubmit(this)">
Birthday:<input type="text" name="birthday" /><br />
<input type="submit" value="submit" />
</form>
使用調節表達! – epascarello 2012-04-15 12:00:15
我該怎麼做? – user1332075 2012-04-15 12:03:22
搜索該網站或使用您最喜愛的搜索引擎進行日期驗證正則表達式JavaScript。 – epascarello 2012-04-15 12:20:10