Acrobat 的日期提取 JavaScript 不起作用

发布于 2024-10-20 00:50:29 字数 830 浏览 2 评论 0原文

详情如下:
我需要什么代码才能从值为 101219488926 的字段中提取 122648 code> 然后以 MM/DD/YY? 格式显示(因此在本例中,新值需要为 12/26/48


这是长版本:
我使用的是磁条阅读器,它从刷卡(驾驶执照)中获取信息,然后使用该信息自动填充 PDF 中的某些字段(名字、姓氏、出生日期等)。

一切正常,但有一个例外:出生日期。即使在技术上也可行,但值的格式如下(假设此人的出生日期是 1948 年 12 月 26 日):

101219488926

需要的是:月份 (12)、日期 (26) 和年份 (19 48)从那个长数字中剥离出来,然后转换为以 MM/DD/YY 格式显示

在 Acrobat 之外,这似乎工作得很好:

var dob = 101219488926;
trimmonth = dob.substring(2,4);
trimday = dob.substring(10,12);
trimyear = dob.substring(6,8);
dob.value = trimmonth + "/" + trimday + "/" + trimyear;

有什么建议吗?

Here's the breakdown:
What code do I need to extract the 12, 26, and 48 from a field whose value is 101219488926 and then display it in the format MM/DD/YY? (So in this case, the new value would need to be 12/26/48)


Here's the long version:
I'm using a mag-stripe reader that takes information from the swiped card (a driver license) and then uses that info to auto-populate certain fields in a PDF (first name, last name, date of birth, etc).

Everything works fine, with one exception: the date of birth. Even that does technically work, but the value is in this format (assuming the person's DOB is 26 December 1948):

101219488926

What I need is: the month (12), day (26), and year (1948) stripped out of that long number, then converted to display in the format MM/DD/YY

Outside of Acrobat, this seems to work just fine:

var dob = 101219488926;
trimmonth = dob.substring(2,4);
trimday = dob.substring(10,12);
trimyear = dob.substring(6,8);
dob.value = trimmonth + "/" + trimday + "/" + trimyear;

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

牵你手 2024-10-27 00:50:29

您在那里的代码不应该工作 - substring是一个String函数,因此您需要将您拥有的数字转换为字符串使其可用。设置 dob.value 也是可疑的,因为 dob 是一个 Number,而数字没有 value 属性。

当然,很明显您没有显示您尝试过的实际代码,但类似这样的代码可能会起作用:

// Appending blank string to type coerce
var dob = 101219488926 + ''; 

// Array.join to glue the numbers together 
// (no reason why you **have** to use this; the original method will work fine too)
dopInput.value = [dob.substring(2,4), dob.substring(10,12), dob.substring(6,8)].join('/');

The code you have there shouldn't work - substring is a String function, so you would need to convert that number you have to a string for it to be available. Setting dob.value is also suspect, since dob is a Number, and numbers do not have a value property.

Of course, it's obvious that you're not showing the actual code you have tried, but something like this would probably work:

// Appending blank string to type coerce
var dob = 101219488926 + ''; 

// Array.join to glue the numbers together 
// (no reason why you **have** to use this; the original method will work fine too)
dopInput.value = [dob.substring(2,4), dob.substring(10,12), dob.substring(6,8)].join('/');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文