Skip to main content
Participating Frequently
Jan 23, 2018 9:48 PM UTC
Answered

Validate number of characters in a field with a message

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!

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Jan 23, 2018 10:11 PM UTC

Add this line after the first one:

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

2 replies

JR Boulay
Community Expert
Community Expert
Jan 24, 2018 9:33 AM UTC

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

Translate
Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Jan 23, 2018 10:11 PM UTC

Add this line after the first one:

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

Translate