Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. clientside validation for date

clientside validation for date

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    imranafsari
    wrote on last edited by
    #1

    Hi all i am using asp.net , C# , ajax1.0 i want to know is it possible to perform client side validation for not allowing date before current date + 5 that is if i am entering a date today(11-09-08) then it should not allow any date before 16-09-08 Please help Thank you.

    imran khan

    G G 2 Replies Last reply
    0
    • I imranafsari

      Hi all i am using asp.net , C# , ajax1.0 i want to know is it possible to perform client side validation for not allowing date before current date + 5 that is if i am entering a date today(11-09-08) then it should not allow any date before 16-09-08 Please help Thank you.

      imran khan

      G Offline
      G Offline
      Gamzun
      wrote on last edited by
      #2

      use regularexpression and set its expression dynamically, so you coup with the current date

      1 Reply Last reply
      0
      • I imranafsari

        Hi all i am using asp.net , C# , ajax1.0 i want to know is it possible to perform client side validation for not allowing date before current date + 5 that is if i am entering a date today(11-09-08) then it should not allow any date before 16-09-08 Please help Thank you.

        imran khan

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        You would have to parse the string and create a Date object from it, and create a Date object to compare it with. Something like:

        // verify string
        if (/^\d\d-\d\d-\d\d$/.test(input)) {
        // get current time
        var today = new Date();
        // get current + 5 days
        var limit = new Date(today.getYear(), today.getMonth(), today.getDay()+5);
        // split input
        var arr = input.split('-');
        // create Date from input
        var inputDate = new Date(parseInt(arr[2],10), parseInt(arr[1],10)-1, parseInt(arr[0],10));
        // compare dates
        if (inputDate >= limit) {
        alert('Date is ok.');
        }
        }

        Despite everything, the person most likely to be fooling you next is yourself.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups