使用javascript进行日期验证 [英] date validation using javascript
本文介绍了使用javascript进行日期验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个日期文本框,如果我输入字符串,则要在该文本框中显示警报消息.
I''ve a textbox for date and in the textbox if I enter string I want it to display an alert msg.
推荐答案
function date(){
var validformat=/^\d{2}\/\d{2}\/\d{4}
/ //Basic check for format validity var returnval=false if (!validformat.test(input.value)) alert("Invalid Date Format. Please correct and submit again."); }
/ //Basic check for format validity var returnval=false if (!validformat.test(input.value)) alert("Invalid Date Format. Please correct and submit again."); }
实际上这是个警告,但是我的日期格式是mon-day-year
因此,如果我输入正确的日期,例如2003年12月11日,则会显示错误消息,因为此(/^ \ d {2} \/\ d {2} \/\ d {4}
actually this one is giving alert, but my date format is mon-day-year
so if i give correct date lik 12-11-2003,it shows error msg, because this one (/^\d{2}\/\d{2}\/\d{4}
/)正在检查lik,这是2003年12月11日.如何获取lik mon-day-year.我可以更改-而不是/
/) is checking lik this 12/11/2003.how can i get lik mon-day-year .can i change the - instead of /
这篇关于使用javascript进行日期验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文