简体   繁体   English

如何在Mirth JavaScript中进行基本日期验证

[英]How to put basic date validations in mirth javascript

We currently accept HL7 data through mirth and one of the field we process is date of birth, which we receive in PID.7.1 segment of HL7. 我们目前通过喜乐接受HL7数据,我们处理的字段之一是出生日期,这是我们在HL7的PID.7.1段中收到的。 Currently we just capture it like - 目前,我们只是像这样捕获它

var vDOB = formatDate(msg['PID.7.1'].toString(),"yyyyMMdd");

How can I validate day , month and year component in the date. 如何验证日期中的日,月和年部分。 And also like it should be greater than today's date. 并且还应该大于今天的日期。

Thanks 谢谢

You can include a function like this: 您可以包含如下功能:

var dateChecker = function(dateStr){
    if(date.length !=8 && !date.match('[0-9]{8}')) return false;//should be number and length 8
    var year = date.substr(0,4);
    var month = date.substr(4,2);
    var day = date.substr(6,2);
    var dateObj = new Date(year,month,day);
    if (dateObj == 'Invalid Date') return false;
    if(dateObj.getTime() - Date.now() > 0) return false;//compare epoch to check if date is less than current date/time
    return true;
}

and then dateChecker(vDOB) should return true/false depending on whether the date is valid or invalid. 然后dateChecker(vDOB)应该返回true / false,具体取决于日期是有效还是无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM