我想要日期格式dd-mm-yy而不是dd-mm-yyyy [英] I want date format dd-mm-yy not dd-mm-yyyy
本文介绍了我想要日期格式dd-mm-yy而不是dd-mm-yyyy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< script 类型 = text / javascript >
函数isValidDate(sText){
var reDate = /(?: 0 [1-9] | [ 12] [0-9] | 3 [01])\ /(?: 0 [1-9] | 1 [0-2])\ /(?: 19 | 20\d {2})/ ;
返回reDate.test(sText);
}
函数validate(){
var oInput1 = document.getElementById(txt1);
if(isValidDate(oInput1.value)){
alert(Valid);
} else {
alert(无效!);
}
}
< / script >
解决方案
您应该像下面这样更改您的注册表达式:
var reDate = new RegExp(< span class =code-string> ^(?: 0 [1-9] | [12] [0-9] | 3 [01]) \\ /(?: 0 [1-9] | 1 [0-2])\ / \d {2}
跨度>);
这是我在html中完成的代码片段,其中我设计了一个日期选择器,它接受dd / mm / yy格式的日期。希望它会对你有所帮助
< html xmlns = http://www.w3.org/1999/xhtml >
< head >
< title > jQuery UI Datepicker - 默认功能< / title >
< link rel = stylesheet href = http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css < span class =code-keyword> / >
< script type = text / javascript src = http://code.jquery.com/jquery-1.9.1.js > < / script > ;
< script type = text / javascript src = http://code.jquery.com/ui/1.10.3/jquery-ui.js > < / script >
< link rel = stylesheet href = /resources/demos/style.css / >
< script type = text / javascript > 跨度>
<script type="text/javascript">
function isValidDate(sText) {
var reDate = /(?:0[1-9]|[12][0-9]|3[01])\/(?:0[1-9]|1[0-2])\/(?:19|20\d{2})/;
return reDate.test(sText);
}
function validate() {
var oInput1 = document.getElementById("txt1");
if (isValidDate(oInput1.value)) {
alert("Valid");
} else {
alert("Invalid!");
}
}
</script>
解决方案
You should change your reg expression like bellow:
var reDate = new RegExp("^(?:0[1-9]|[12][0-9]|3[01])\/(?:0[1-9]|1[0-2])\/\d{2}
");
Here is a code snippet i have done in html in which i have designed a date picker which accepts the date in the format dd/mm/yy. Hopes it will help you
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>jQuery UI Datepicker - Default functionality</title> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"/> <script type="text/javascript"src="http://code.jquery.com/jquery-1.9.1.js"></script> <script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <link rel="stylesheet" href="/resources/demos/style.css"/> <script type="text/javascript">
这篇关于我想要日期格式dd-mm-yy而不是dd-mm-yyyy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文