cosmo-ui
Version:
Common React components
33 lines • 1.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var moment = require("moment");
/**
* Validate a UK postcode using regex
*
* @param postcode
*/
exports.validatePostcode = function (postcode) {
/* tslint:disable */
var str = '(GIR 0AA)|((([A-Z-[QVX]][0-9][0-9]?)|(([A-Z-[QVX]][A-Z-[IJZ]][0-9][0-9' +
']?)|(([A - Z - [QVX]][0 - 9][A - HJKPSTUW]) | ([A - Z - [QVX]][A - Z - [IJZ]][0 ' +
'- 9][ABEHMNPRVWXY])))) [0 - 9][A - Z - [CIKMOV]]{2 })';
/* tslint:enable */
var regex = new RegExp(str);
if (regex.test(postcode)) {
return [];
}
return ['* Not a valid UK postcode'];
};
exports.INPUT_DATE_FORMAT = 'YYYY-MM-DDTHH:mm';
/**
* Helper function for client's wishing to pre-initialize the value
* This ensures it is in the format required for datetime-local
*
* @param value
*/
exports.formatDateForInput = function (value) {
var parsed = moment(value);
var formatted = parsed.format(exports.INPUT_DATE_FORMAT);
return formatted === 'Invalid date' ? value : formatted;
};
//# sourceMappingURL=forms.js.map