• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Validate number of characters in a field with a message

New Here ,
Jan 23, 2018 Jan 23, 2018

Copy link to clipboard

Copied

Greets, all:

I found this formula for validating the number of charcters in a field:

event.rc = (event.value=="" || /^\d{9}$/.test(event.value));

...but in my case I want to make sure there's only four characters in the field (for the year number). It's easy enough to see that I need to replace the 9 with a 4, however, how do I code it so if four digits aren't entered for the year a warning pops up that says, "You must enter a four-digit year"?

TIA for your help!

TOPICS
Acrobat SDK and JavaScript

Views

336

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 23, 2018 Jan 23, 2018

Add this line after the first one:

if (!event.rc) app.alert("You must enter a four-digit year.");

Votes

Translate

Translate
Community Expert ,
Jan 23, 2018 Jan 23, 2018

Copy link to clipboard

Copied

Add this line after the first one:

if (!event.rc) app.alert("You must enter a four-digit year.");

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2018 Jan 24, 2018

Copy link to clipboard

Copied

LATEST

This script does not prevent the "0000" fake year…

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines