Skip to content

Commit 4974628

Browse files
committed
adding the validation for manual input on customer create, on frontend
1 parent c5d1aee commit 4974628

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

app/code/Magento/Customer/Block/Widget/Dob.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ public function getHtmlExtraParams()
267267
$validators['validate-date'] = [
268268
'dateFormat' => $this->getDateFormat()
269269
];
270+
$validators['validate-dob'] = true;
271+
270272
return 'data-validate="' . $this->_escaper->escapeHtml(json_encode($validators)) . '"';
271273
}
272274

app/code/Magento/Customer/view/frontend/templates/widget/dob.phtml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,11 @@ $fieldCssClass .= $block->isRequired() ? ' required' : '';
3535
<?php endif; ?>
3636
</div>
3737
</div>
38+
39+
<script type="text/x-magento-init">
40+
{
41+
"*": {
42+
"Magento_Customer/js/validation": {}
43+
}
44+
}
45+
</script>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require([
2+
'jquery',
3+
'moment',
4+
'jquery/ui',
5+
'jquery/validate',
6+
'mage/translate',
7+
], function($, moment) {
8+
'use strict';
9+
$.validator.addMethod(
10+
"validate-dob",
11+
function (value) {
12+
if (value === '') {
13+
return true;
14+
}
15+
return moment(value).isBefore(moment());
16+
},
17+
$.mage.__('The Date of Birth should not be greater than today.')
18+
);
19+
});

0 commit comments

Comments
 (0)