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.

Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.