Welcome, Guest
Username: Password: Remember me

TOPIC: Date field format validation

Date field format validation 29 Jul 2016 21:18 #14338

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
Hi there,

I have noticed that a date field is not correctly validated if entered manually (not via the calendar icon)

I have fixed that by adding the following code to the xxx_form.php file, just below the <?php $fieldset = ...
<script>
jQuery.validationEngineLanguage.allRules.date = {
    "regex" : /^(0[1-9]|[12][0-9]|3[01])[\/\-](0[1-9]|1[012])[\/\-]\d{4}$/,
    "alertText" : '<span class="msg-prefix">• </span>Incorrect value'
};
</script>
This requires the field to be in dd-mm-yyyy or dd/mm/yyyy

Also, the field has to be extended.
You can do that by forking the form.xml:
		<field name="fieldname"
				alias="fieldname"
				label="LABEL"
				filter="STRING"
				type="ckcalendar"
				format="d-m-Y"
				required="true"
				placeholder="dd-mm-yyyy"
				class="validate[required,custom[date]]"/>
Extra is: placeholde and class part (required can be omitted for non required fields)

Greets
The administrator has disabled public write access.
The following user(s) said Thank You: admin
Time to create page: 0.087 seconds

Get Started