Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Website Date Validation

  • 20-11-2007 8:09pm
    #1
    Registered Users, Registered Users 2 Posts: 8,679 ✭✭✭


    Ok so here is my conundrum:

    I have a site that has the following, start date / time and end date / time. Now I need to validate it by making sure the end date / time is greater than the start time / date. Whats the best way to go about this , javascript..... ?

    Cheers for any advice.

    Will


Comments

  • Registered Users, Registered Users 2 Posts: 3,594 ✭✭✭forbairt


    javascript is only to be used as a client side nice to have feature
    [ok javascript can be a whole lot more I'm aware but in this case]

    What you really want to do is have the form you are passing the two dates to validate the input.

    What language are you using server side ?


  • Registered Users, Registered Users 2 Posts: 8,679 ✭✭✭Chong


    I am using ASP with VB. As it stands I have a start date field, you pick via a calendar picker, it then places the date picked back in a text box, in the following format : DD/MM/YYYY.

    The same goes for the end date, but I also have a start time after the start date in the form of two combo boxes for hour and minute, same goes for end time. Now the check needs to see if the end date and time is greater than the start date and time. If its not it needs to alert the user so. You see I know what to do in essense but do not know how to go about it.

    Hope this makes sense.


  • Registered Users, Registered Users 2 Posts: 3,594 ✭✭✭forbairt


    well you've got two places here that you can inform the user

    The front end can inform the user and for this you use javascript form validation for this ...

    Something like http://javascript.internet.com/forms/val-date.html should get you started on that

    On the back end then ... I'm lost ... I haven't done much asp so what you want to do is convert your two dates into numbers and compare the two making sure your to date is greater than your from date ...


    Think about what you're trying to do ..
    Year Month Day Hours Minutes Seconds (though you probably aren't counting seconds)

    Convert the whole thing to seconds

    1 minute = 60 seconds
    1 hour = 60 minutes = 60 x 60
    1 day = 24 x 60 minutes = 24 x 60 x 60
    and so on ...

    at the end you have 1 number in seconds and another number in seconds

    if ( yourToDate > yourFromDate ) all is good

    There are probably date functions to deal with this but this should point you in the right direction as to what you should be thinking about doing

    On an error then ... Print a message to the user and fill in the form details they entered.

    On no error ... do whatever you have to do with your form date :)


  • Registered Users, Registered Users 2 Posts: 8,679 ✭✭✭Chong


    Again cheers for the advice Forbairt , roll on Work tomorrow :)


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    You don't even need to convert to seconds, IIRC ASP/VB has a date object (which could probably convert to seconds for you if needed) and you can do comparisond directly on them.

    Dim date1 = new Date(request("fromDate"))
    Dim date2 = new Date(request("toDate"))

    if date2 < date1 then
    ...
    ...

    etc


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 3,594 ✭✭✭forbairt


    stevenmu wrote: »
    You don't even need to convert to seconds, IIRC ASP/VB has a date object (which could probably convert to seconds for you if needed) and you can do comparisond directly on them.
    etc

    I thought it would have still it doesn't hurt to know in a little bit more about what you are trying to do or to come up with alternatives to keep the mind fresh :)


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Personally I validate data on the client side only to enhance the user experience, in that they don't have to wait for a post back. However there's nothing to stop them from switching of the javascript and sending dodgy data to try an break the application. I always validate on the server-side regardless as the user can't by-pass this.


  • Registered Users, Registered Users 2 Posts: 413 ✭✭ianhobo


    forbairt wrote: »
    javascript is only to be used as a client side nice to have feature.
    What language are you using server side ?
    if possible, you should always do whatever validation you can client side!!!
    it saves your server having to waste time doing un-nessecary validation that can be done by the client!
    Imagine if you were serving a million pages a day. If every one enters an invalid data first time, they have to submit the page for your server to validate it, your server then has to perform the validation, and then reserve the page for further (re) validation! you've just doubled the amount of data the you serve, completely un-necessarily
    A simple client side script would ensure that any data that is sent to you is pre-validated saving you bandwidth, server time, database update time, the users time! on and on....


  • Registered Users, Registered Users 2 Posts: 413 ✭✭ianhobo


    Evil Phil wrote: »
    Personally I validate data on the client side only to enhance the user experience, in that they don't have to wait for a post back. However there's nothing to stop them from switching of the javascript and sending dodgy data to try an break the application. I always validate on the server-side regardless as the user can't by-pass this.

    I'm not saying don't server side validate, my point is that a client side validation will prevent data from having to be re-served, wasting time and money. 99 times out a 100, you shouldnt have a problem server side if you validated client side


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    forbairt wrote: »
    I thought it would have still it doesn't hurt to know in a little bit more about what you are trying to do or to come up with alternatives to keep the mind fresh :)
    Yep, I agree completely, it's always good to look at a full algorithm to do what you want before using inbuilt functionality


  • Advertisement
Advertisement