Restrict text boxes to enter dates in YYYY-MM-DD format, text box yyyy-mm-dd

Source: Internet
Author: User

Restrict text boxes to enter dates in YYYY-MM-DD format, text box yyyy-mm-dd

Text input boxes sometimes have restrictions on the input text, such as limiting the date of the input YYYY-MM-DD format, can be achieved through regular expressions

Function IsDate (str) {var reg =/^ (\ d {4})-(\ d {2})-(\ d {2}) $ /; if (str = '') {return false;} var arr1_reg.exe c (str); if (! Reg. test (str) | parseInt (RegExp. $2) >=12 | parseInt (RegExp. $3) >=31) {return false;} return true ;}

Arr=reg.exe c (str), arr is an array that places the matched text in the first element and the Child Matching Element in the following element:

For example, str = ", then the corresponding arr = [" "," 2015 "," 06 "," 05 "]

RegExp. $2 is equivalent to arr [2], that is, after arr is returned, the corresponding RegExp is also assigned a value, which is the same as the value in arr.

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.