Skip to content

verifyDateMMDDYYYY() Helper Method

The verifyDateMMDDYYYY() Helper Method module provides a helper function that takes a string as an argument and returns a Boolean value of true if the string matches a MM/DD/YYYY syntax, and false if it does not match the syntax.

Import

To import the verifyDateMMDDYYYY() Helper Method:

javascript
import { verifyDateMMDDYYYY } from '@obewds/vueventus'

Arguments

Returns: String

ArgsTypeStatusDescription
dataStringRequiredChecks string argument against regex match for MM/DD/YYYY format

Use Example

javascript
console.log(
    verifyDateMMDDYYYY('01/01/0001'),
    verifyDateMMDDYYYY('12/31/9999'),
    verifyDateMMDDYYYY('06/02/2020'),
    verifyDateMMDDYYYY('10/28/1899')
)
// all return true

console.log(
    verifyDateMMDDYYYY('01-01-0001'),
    verifyDateMMDDYYYY('12.31.9999'),
    verifyDateMMDDYYYY('12/32/1899'),
    verifyDateMMDDYYYY('00/01/1899')
)
// all return false

Module Code

ts
// ./src/validation/verifyDateMMDDYYYY.ts

import verifyType from './verifyType'

export default function ( data: string ): boolean {

    if ( verifyType(data, 'string') ) {

        // accepts date with a year between 0001 and 9999
        return data.length === 10 && 
            /^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/[0-9]{4}$/.test(data) ? true : false

    }

    return false

}

Released under the MIT License