Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Javascript validation

Posted on 2014-04-01
2
Medium Priority
?
122 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…
Suggested Courses

886 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