We help IT Professionals succeed at work.

Date validation does not work?

apwbe
apwbe asked
on
Medium Priority
440 Views
Last Modified: 2013-12-24
I have two forms that manipulate a SQL Server database. One form creates/adds new records and the other updates the records. Each form has validation for the date fields. The form that creates/adds a new record works well and will give a message before submitting if the dates are entered in the wrong format. the code sample is:

<cfinput type="text" name="AssmApproveDate" message="Date must be mm/dd/yy format" validate="date" pattern="mm/dd/yy" value="" size="8" maxlength="8" tabindex="4">

The update form has the date values populated from the database. If no date changes are made the submit will work fine but if a wrong date format is entered or a date changed to a wrong format the validation does not work and the form is submitted resulting in a CF error for the stored procedure on the processing page that states that a the value can not be added to the DateTime field. Here is a code sample on this form:

<cfinput type="text" name="AssmApproveDate" message="Assembly Approval Date must be mm/dd/yy format" validate="date" pattern="mm/dd/yy" size="8" maxlength="8" tabindex="4" value='#DateFormat(Select_record.AssmApproveDate, "m/d/yy")#'>

Any ideas why the validate will not work on this second page?
Comment
Watch Question

Commented:
I think there may be some confusion with the validation going on.

You have both a pattern attribute and a validate attribute.  You actually only need one of these and not both.
"pattern" needs a valid regular expression.  Unfortunately, "mm/dd/yy" is not valid regex, or at least not for what you actually want to happen.
"validate" of type "date" used clientside will match "a US date of the format mm/dd/yy mm-dd-yy or mm.dd.yy, with 1-2 digit days and months, 1-4 digit years." (from the Adobe/Macromedia livedocs)

Try removing the pattern attribute from the cfinput on both forms.

Also, you probably should use the same format as you're expecting when you put the date from the database into the cfinput value.  At the moment you have #DateFormat(Select_record.AssmApproveDate, "m/d/yy")#  when really you should have #DateFormat(Select_record.AssmApproveDate, "mm/dd/yy")#

Hope that helps.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Mr Nil,

Thank you for you quick response to this question. I new it would be something simple but really needed a solution fast as i was under the gun.

Godd luck and thanks again!

Warren
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.