Ask a Question related to Coldfusion - Getting Started, Design and Development.

  1. #1

    Default Date Validation

    I'm trying to find some Coldfusion code that will allow me to validate a date
    to make sure that it's in MM/DD/YY format and is actually a valid date.
    Everything that I've read about IsDate says that it's faulty and doesn't check
    to see if the date being checked is actually real. Is anyone aware of code that
    does this?

    cfKismet Guest

  2. Similar Questions and Discussions

    1. [PHP] Date Validation, Kinda'
      Now that I'm thinking about it, what is your goal with this? Is it to make sure the date entered is within a certain range when compared to another...
    2. combo box date validation
      Hi, As per our requirement, we need to put combo boxess for date input. we are giving the user to input as dd month year format from the given...
    3. Date Range Validation
      Hello; CL_FRST (08/10/2004) and CL_LST (05/24/2005) holds the beginning and ending date of school calendar which is also prepopulated for every...
    4. Date Validation, Kinda'
      Howdy, Has anyone written any date validation function or sequence. I have looked around, but haven't found anything. I am cobbling togather...
    5. date validation?
      How to write an IsDate function that actually checks for a particular date format? Using try-catch on Convert.ToDateTime(sDate) doesn't catch...
  3. #2

    Default Re: Date Validation

    What version of CF? I haven't had any issues with IsDate, but you could also use IsValid with the date attribute
    SafariTECH Guest

  4. #3

    Default Re: Date Validation

    Not sure if it's still the case, but, in version 4.5 isDate("apr 31") would
    return true. For cfKismet, if you are talking about a text input field, and
    you have CF version 7, set the mask attribute to 99/99/99 and the validate
    field to date.

    Dan Bracuk Guest

  5. #4

    Default Re: Date Validation

    Sorry, I should have been more specific. The page that processes all of my
    Coldfusion validation does it free-form as not all of my validation can be
    accomplished through masks. Can someone confirm whether or not IsDate actually
    works as intended in Coldfusion 7? (i.e. doesn't just validate the format, but
    actually if its a real date or not)

    cfKismet Guest

  6. #5

    Default Re: Date Validation

    ^^^ That's why I asked about version ... it's been ages since I have seen anything about improper date validations
    SafariTECH Guest

  7. #6

    Default Re: Date Validation

    isDate never validated format. It takes a string and returns true if it can
    turn that string into a date and false if it can't. I've never seen it return
    false on an actual date. The only time I saw it return true on a non date was
    for the string "apr 31". That was in version 4.5. If you are working version
    7, try it. See if it still returns false.

    Just so you know, even though we know that you can trick isDate with at least
    one string, we have been using it for years and not once has a real person
    caused it to return true with a non-date.

    Originally posted by: cfKismet
    Sorry, I should have been more specific. The page that processes all of my
    Coldfusion validation does it free-form as not all of my validation can be
    accomplished through masks. Can someone confirm whether or not IsDate actually
    works as intended in Coldfusion 7? (i.e. doesn't just validate the format, but
    actually if its a real date or not)



    Dan Bracuk Guest

  8. #7

    Default Re: Date Validation

    Thanks for the help, guys. I'm using IsDate now, but I still have a problem
    with it. Users on my site enter a date in a text field in MM/DD/YYYY format
    which then gets entered into a database. The problem is that if they enter
    something like 13/05/2005, which according to the formatting I'm looking for is
    invalid, IsDate lets it pass through as 05/13/2005. Obviously, IsDate can
    convert it to a valid date, but I still need to catch the error somehow. Is
    there a way to force it to be interpreted a certain way?

    cfKismet Guest

  9. #8

    Default Re: Date Validation

    Yes.

    Change your form. Among the ways that will work are:
    a. have separate form fields for day, month and year.
    b. use a flash form with a datepicker
    c. use a javascript popup calendar
    Dan Bracuk Guest

  10. #9

    Default Re: Date Validation

    Thanks, Dan. I think I might opt to use seperate date fields, just for ease of
    mind. One more question, though. I'm using that same date in a DateCompare
    function, so of course when the date isn't formatted correctly, Coldfusion
    errors out even before it gets to the IsDate function. I've had this problem
    before with variables that might not exist and have been able to use cfparam to
    fix that, but I don't know how to get around this.

    To summarize, I'm using DateCompare to make sure that the date they supply
    isn't later than another date, but if they supply an invalid date, Coldfusion
    tries to process it and the page fails before IsDate can even catch it. Any
    thoughts?

    cfKismet Guest

  11. #10

    Default Re: Date Validation

    Datecompare?? Didn't realize there was such a function. Amazing what you
    learn by volunteering to answer questions.

    In any event, we have some bread and butter applications where I work. One
    type is where the user is presented with a form and asked to submit a start and
    end date. If they do it correctly, they find out what happened between those
    two dates.

    We do this so often that, way back when, I wrote a custom tag (patting myself
    on the shoulder) that:
    1. Ensures both form fields are valid dates.
    2. Ensures the end date is equal to or later than the start date.
    3. Ensures both dates co-incide with when data is actually available.
    4. Makes sure they are not too far apart.
    5. Converts them to yyyy-mm-dd format.

    I just temporily changed my profile so that I will accept private messages at
    work (where I currently am not). If you ask, I'll send it to you. Ask
    quickly, I am isolating myself again tomorrow.


    Dan Bracuk Guest

  12. #11

    Default Re: Date Validation

    Hi Dan...just sent you a private message, but I'm not sure what to expect...never used the feature here. I have my own settings set to receive private messages as well
    cfKismet Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139