Solved

Javascript validation

Posted on 2014-04-01
2
118 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Google Tag Manager - Add Trigger Using Div class 22 51
Sending ASP to server side 8 28
links not working 2 25
Link Anchor Not working 9 43
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

680 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