The regular expression summary of the time format of the commander in jquery _jquery

Source: Internet
Author: User

jquery is used in the code, and the incoming parameter is the input object of jquery selection. Principle: First use the regular match, then extract the seconds and minutes to see whether it is within the normal range.

Copy Code code as follows:

/**
* Detection time is in line with the format
* @param {Object} timetextbox
*/
function Checktime (timetextbox) {
var time = Timetextbox.val ();
var regtime =/^ ([0-2][0-9]):([0-5][0-9]):([0-5][0-9]) $/;
var result = false;
if (Regtime.test (time)) {
if (parseint (regexp.$1) <) && (parseint (regexp.$2) <) && (parseint (regexp.$3) < 60)) {
result = true;
}
}
if (result) {
$ ("#errmsg"). HTML ("");
}else {
Timetextbox.attr ({
Value: ""
});
Timetextbox.focus ();
$ ("#errmsg"). HTML ("Time format error");
}
return result;
}

Example 2

Direct use of js+ regular expressions for instance

Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<title> New Document </title>
<meta name= "generator" content= "EditPlus" >
<meta name= "Author" content= "" >
<meta name= "Keywords" content= "" >
<meta name= "Description" content= "" >
<body>
Date of birth: <input id= "Birthday" name= "Birthday" "type=" text "value=" "onblur=" checkdate (); " />
</body>
<script>
var date_format =/^[0-9]{4}-[0-1]? [0-9] {1}-[0-3]? [0-9] {1}$/;
function Checkdate () {
var birthday = document.getElementById ("Birthday"). Value;
if (Date_format.test (birthday)) {
Alert ("The date you entered is in the correct format");
} else {
Alert ("Sorry, the date you entered is in an incorrect format, the correct format should be" 2012-01-01 ");
}
}
</script>


jquery Verification Time

A regular expression collection of validation times

Date format yyyy
Patternsdict.date_y=/^ (\d{4}) $/;

Date format yyyy-mm
Patternsdict.date_ym=/^ (\d{4})-(0\d{1}|1[0-2)) $/;

Date format YYYY-MM-DD
Patternsdict.date_ymd=/^ (\d{4})-(0\d{1}|1[0-2))-(0\d{1}|[ 12]\D{1}|3[01]) $/;

Time format HH
patternsdict.time_h=/^ (0\d{1}|1\d{1}|2[0-3]) $/;

Time Format hh:mm
patternsdict.time_hm=/^ (0\d{1}|1\d{1}|2[0-3]):([0-5]\d{1}) $/;

Time Format Hh:mm:ss
patternsdict.time_hms=/^ (0\d{1}|1\d{1}|2[0-3]): [0-5]\d{1}:([0-5]\d{1}] $/;

Format is the time, that is, the first two bits can not be less, and can not be greater than 23, the time and the following can not be greater than 59, must be written in 16:02:01 and not for 16:2:1

[0-2] [0-3]:[0-5][0-9]:[0-5][0-9]

With CompareValidator
Operator set into Datetypecheck
Type is set to date

Here's how to judge Yyyy-mm-dd in this format, basically taking into account the leap year and February, but I've forgotten where I found it.

^ ((1[6-9]| [2-9]\d) \d{2})-(0?[ 13578]|1[02])-(0?[ 1-9]| [12]\d|3[01]) | (((1[6-9]| [2-9]\d) \d{2})-(0?[ 13456789]|1[012])-(0?[ 1-9]| [12]\d|30)] | (((1[6-9]| [2-9]\d) \d{2}) -0?2-(0?[ 1-9]|1\D|2[0-8]) | (((1[6-9]| [2-9]\d) (0[48]|[ 2468][048]| [13579] [26]) | ((16| [2468] [048]| [3579] [26]) 00)) $ -0?2-29-)

The following is the addition of time verification

^ ((1[6-9]| [2-9]\d) \d{2})-(0?[ 13578]|1[02])-(0?[ 1-9]| [12]\d|3[01]) | (((1[6-9]| [2-9]\d) \d{2})-(0?[ 13456789]|1[012])-(0?[ 1-9]| [12]\d|30)] | (((1[6-9]| [2-9]\d) \d{2}) -0?2-(0?[ 1-9]|1\D|2[0-8]) | (((1[6-9]| [2-9]\d) (0[48]|[ 2468][048]| [13579] [26]) | ((16| [2468] [048]| [3579] [26]) 00)) ( -0?2-29-)) (20|21|22|23|[ 0-1]?\d): [0-5]?\d:[0-5]?\d$


aspx page: <%# databinder.eval (Container.DataItem, "company_ureg_date")%>
Displayed as: 2004-8-11 19:44:28
I only want: 2004-8-11 "

<%# DataBinder.Eval (Container.DataItem, "company_ureg_date", "{0:yyyy-m-d}")%>

How should it be changed?


"Format Date"
Take it out, it's usually object.
((DateTime) objectfromdb). ToString ("Yyyy-mm-dd");


A. The following correct input format: [2004-2-29], [2004-02-29 10:29:39 PM], [2004/12/31]

^ ((\d{2} ([02468][048]) | ( [13579] [26])) [\-\/\s]? (((0? [13578]) | (1[02]) [\-\/\s]? ((0?) [1-9]) | ([1-2][0-9]) |
(3[01])) | ((0? [469]) | (11)) [\-\/\s]? ((0?) [1-9]) | ([1-2][0-9]) | (30)) | (0?2[\-\/\s]? ((0?) [1-9]) | ([1-2][0-9])))
| (\d{2} ([02468][1235679]) | ( [13579] [01345789])) [\-\/\s]? (((0? [13578]) | (1[02]) [\-\/\s]? ((0?) [1-9]) | ([1-2][0-9])
| (3[01])) | ((0? [469]) | (11)) [\-\/\s]? ((0?) [1-9]) | ([1-2][0-9]) | (30)) | (0?2[\-\/\s]? ((0?) [1-9]) | (1[0-9]) | (2[0-8])))) (\s ((0?[ 1-9]) | (1[0-2]) \:([0-5][0-9]) ((\s) | ( \:([0-5][0-9]) \s)) ([am| pm|am|pm]{2,2}))? $

B. The following correct input format: [0001-12-31], [9999 09 30], [2002/03/03]

^\d{4}[\-\/\s]? ((((0[13578]) | (1[02]) [\-\/\s]? (([0-2][0-9]) | (3[01])) | (((0[469]) | (11)) [\-\/\s]? (([0-2][0-9]) | (30)) | (02[\-\/\s]? [0-2] [0-9])) $

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.