Solved

Javascript validation

Posted on 2014-04-01
2
116 Views
Last Modified: 2014-04-03
I want to validate this format 04/01/2014 01:30 if its type in and submitted.
0
Comment
Question by:smares323
2 Comments
 
LVL 22

Accepted Solution

by:
Mrunal earned 500 total points
ID: 39971852
hi
please refer below code:

http://jsfiddle.net/8m63c/

<form>
    <p>Enter date</p>
    <input type="text" id="test1" value="02/05/2013 11:23"/>        
    <br /><br />
    <input type="button" id="btnSubmit" value="Submit" />
</form>

Open in new window


    $('#btnSubmit').click(function(){
        if(validateDate($('#test1').val())) {
            $('#test1').css('background', '#0F0');
        } else {
            $('#test1').css('background', '#F00');
        }
    });


function validateDate(testdate) {
    //alert(testdate);
    var date_regex = /^\d{2}\/\d{2}\/\d{4}[ ]\d{2}[:]\d{2}$/ ;
    return date_regex.test(testdate);
}

Open in new window

0
 

Author Closing Comment

by:smares323
ID: 39976938
great advice
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question