Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
onDateInputChange(event: any): void { const raw: any = (event && (event.currentTarget?.value ?? event.target?.value ?? (typeof event === 'string' ? event : undefined))) ?? ''; const val: string = String(raw).trim(); const ctrl: AbstractControl = this.fields && this.fields['proxy_date']; const applyInvalid: () => void = (): void => { if (!ctrl) { return; } ctrl.setValue(null, { emitEvent: false }); ctrl.updateValueAndValidity({ onlySelf: true, emitEvent: false }); const errs: { [key: string]: any } = { ...(ctrl.errors || {}) }; errs['invalidDate'] = true; ctrl.setErrors(errs); ctrl.markAsTouched(); } const removeInvalidFlagIfPresent: () => void = (): void => { if (!ctrl) { return; } const errs = { ...(ctrl.errors || {}) }; if (errs['invalidDate']) { delete errs['invalidDate']; } ctrl.setErrors(Object.keys(errs).length ? errs : null); }; if (!val) { applyInvalid(); return; } const match: RegExpMatchArray|null = val.match(/^\s*(\d{1,2})\s*[.\-\/]\s*(\d{1,2})\s*[.\-\/]\s*(\d{4})\s*$/); if (!match) { applyInvalid(); return; } const day: number = parseInt(match[1], 10); const month: number = parseInt(match[2], 10); const year: number = parseInt(match[3], 10); if (!Number.isFinite(day) || !Number.isFinite(month) || !Number.isFinite(year)) { applyInvalid(); return; } if (month < 1 || month > 12) {applyInvalid(); return;} const daysInMonth: number = new Date(year, month, 0).getDate(); if (day < 1 || day > daysInMonth) {applyInvalid(); return;} const parsed = new Date(year, month - 1, day); if (parsed.getFullYear() !== year || parsed.getMonth() !== month - 1 || parsed.getDate() !== day || isNaN(parsed.getTime()) ) { applyInvalid(); return; } if (ctrl) { ctrl.setValue(parsed, { emitEvent: false }); ctrl.updateValueAndValidity({ onlySelf: true, emitEvent: false }); removeInvalidFlagIfPresent(); } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)