+ Reply to Thread
Results 1 to 5 of 5

Thread: date validation

  1. #1
    fox.heart.lucille30 is offline x10Hosting Member fox.heart.lucille30 is an unknown quantity at this point
    Join Date
    Sep 2010
    Posts
    3

    date validation

    can someone help me
    i need a code/script for date validation either php or javascript

    the user cant enter a date that already has passed by or the current date
    example if today is oct 1 2010
    and the user entered oct 1 2010 or sept 22 2010, the system should not accept the input and display an error

    and the user cant enter a date that is invalid like sept 34, 2004

  2. #2
    bhupendra2895's Avatar
    bhupendra2895 is offline x10 Elder bhupendra2895 is an unknown quantity at this point
    Join Date
    Jun 2010
    Location
    India
    Posts
    554

    Re: date validation

    This is programming help section and if you need help then you should write some of the code here you wrote to solve this problem.How you can expect us to write entire code for you for free.

    See date() in php.net, it should be helpful to you.
    Liked this? Click on the icon on the bottom of post to make me .

  3. #3
    fox.heart.lucille30 is offline x10Hosting Member fox.heart.lucille30 is an unknown quantity at this point
    Join Date
    Sep 2010
    Posts
    3

    Re: date validation

    Quote Originally Posted by bhupendra2895 View Post
    This is programming help section and if you need help then you should write some of the code here you wrote to solve this problem.How you can expect us to write entire code for you for free.

    See date() in php.net, it should be helpful to you.
    Oh sorry
    I thought I can beg a code here for free, guilty for not reading the rules
    Im still trying to search on the net
    I'll try date() then

  4. #4
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: date validation

    Dates are tricky things. Well, not dates as such, but the eighteen thousand different ways that users have come up with to express dates as text. Most Americans will use the format "mm/dd/yyyy" or "m/d/yyyy"; the English and some English Canadians tend to use "dd/mm/yyyy" (the rest of English Canada has gotten rather used to the default US settings for Windows); French Canadians and most Europeans will use "yyyy-mm-dd" (though some will use "yyyy.mm.dd" just to annoy programmers); and some people just plain like to spell out the month, either in full or abbreviated and may decide to throw the weekday in just for kicks. For the sake of your own sanity, pick one and only one format that you'd be willing to accept, and enforce that decision with an iron fist.

    As for validation, you want both JavaScript and PHP, not one or the other. JavaScript validation happens immediately in the browser, so the user doesn't have to wait for several seconds while your server-side code decides whether the values they entered are acceptable. It's much more user-friendly to give them immediate feedback when you can. (There are some things that can only be validated at the server. You can tell whether a field has been filled in or not, but you have to ask the server if the value is a duplicate, for instance.) But JavaScript validation is only a user convenience -- there is no guarantee that the user has JavaScript enabled, or that s/he might not be the type to fire up a JS debugger and skip through your validation for some reason (usually malicious or, in the case of corporate apps, in order to "time travel" and sign off on something they were supposed to have done last week). So you need to do real validation at the server as well.

    In both cases, you are going to want to do two things. First, you'll want to check the value the user enters against a regular expression to make sure that it meets your desired format. Then you'll want to pull the text apart into its component parts (the day, the month, and the year) and create a real date object from those values. Both the JavaScript constructor "new Date()" and the PHP function "mktime()" let you build a date using parts. If you don't use any time components (just the day, month and year, with zeros in the hour, minute and second slots), the date you create will be at the stroke of midnight at the beginning of the day. You can compare that against a simple value (new Date() with no arguments in JavaScript, date() in PHP). Actually writing the code to do that would require knowing what date format you are using.

    Give it a shot, and if you have problems, post your code. We'll be happy to help.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  5. #5
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: date validation

    Define what you mean by "code"
    Is this a homework assignment?
    Is this something you want to put on a webpage and validate either by javascript or PHP?
    Do you want the code for an input form?
    Nothing is always absolutely so.

+ Reply to Thread

Similar Threads

  1. Javascript Validation
    By as4s1n in forum Programming Help
    Replies: 4
    Last Post: 06-21-2010, 02:38 PM
  2. Replies: 1
    Last Post: 03-15-2010, 11:23 AM
  3. Validation
    By ibrooker in forum Free Hosting
    Replies: 1
    Last Post: 03-03-2010, 08:07 AM
  4. Form Validation Using PHP.. Help
    By whizynix02 in forum Programming Help
    Replies: 7
    Last Post: 08-18-2009, 11:08 PM
  5. Validation errors!
    By intertec in forum Programming Help
    Replies: 4
    Last Post: 07-08-2008, 07:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers