Control in B/s program design, often need to input a date or time to an input box, and verify that the input is valid. The usual authentication method is to perform string validation at the time of submission, or to submit the error if it is a valid date or time. Alternatively, the input of the date time into several Drop-down list boxes, which are selected by the user on the day of the month.
here gives a date-time input validation script written in JavaScript. This script can make a normal input box into a date time input box. You can only enter a date-time format string in this input box without allowing you to enter any other characters. When you enter illegal characters, it is not irresponsible to eject the error dialog box, but completely filter out your input to ensure that the contents of your input box is absolutely legitimate date-time format.
In fact, you can add other validation functions to this script to allow the script to control input from other types of formats, such as numbers, emails, user IDs, and so on.
The
code is as follows:
<script>
function Istime (str) {
var a = Str.match (/^ (\d{0,2}):(\d{0,2}):(\d{0,2);
if (a = = null) return false;
if (a[1]>=24 | | a[2]>=60 | | a[3]>=60) return FALSE;
return true;
}
function Isdatetime (str) {
var a = Str.match (/^ (\d{0,4})-(\d{0,2})-(\d{0,2}) (\d{0,2}):(\d{0,2}):(\d{0,2);
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.