Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Javascript for 5 or 9 zip code?

Avatar

Avatar
Validate 1
Level 1
hy9fesh
Level 1

Likes

0 likes

Total Posts

9 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
hy9fesh
Level 1

Likes

0 likes

Total Posts

9 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Affirm 1
View profile
hy9fesh
Level 1

24-04-2015

I have a form where I want to do a five to nine zip code; if the user inputs anything else, it is will be deemed invalid and the field will be empty when the user presses "enter."

So far, in the change event, I have the following script that only allows 9 digits, meaning the user cannot input more than 9 digits:

     var maxLength = 9;

     if(xfa.event.newText.length >maxLength)xfa.event.change = "";

Then in the exit event, I have the following script that only allows numerical digits:

if(this.rawValue==null){this.execValidate();}

if (!/^[0-9]{5,9}$/i.exec(this.rawValue)) {

  this.rawValue= null;

}

The problem is that it's still allowing entries like "123456" or "1234567" or "12345678." I only want users to be able to enter a 5-digit or 9-digit zip code.

Please let me know if there is anything I can do to resolve this issue.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 1
Level 1
hy9fesh
Level 1

Likes

0 likes

Total Posts

9 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
hy9fesh
Level 1

Likes

0 likes

Total Posts

9 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Affirm 1
View profile
hy9fesh
Level 1

28-04-2015

I have the nine-digit pattern set up in LiveCycle (e.g.,12345-1234), so I revised the code a bit and it shows up: if(!/^\d{5}(\d{4})?$/.test(this.rawValue))

Thanks!

Answers (2)

Answers (2)

Avatar

Avatar
Validate 1
Level 4
mouslander
Level 4

Likes

23 likes

Total Posts

298 posts

Correct Reply

27 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 4
mouslander
Level 4

Likes

23 likes

Total Posts

298 posts

Correct Reply

27 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
mouslander
Level 4

27-04-2015

this actually works I used it on Validate

if(!/^\d{5}(-\d{4})?$/.test(this.rawValue))

Avatar

Avatar
Validate 1
Level 4
mouslander
Level 4

Likes

23 likes

Total Posts

298 posts

Correct Reply

27 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 4
mouslander
Level 4

Likes

23 likes

Total Posts

298 posts

Correct Reply

27 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
mouslander
Level 4

27-04-2015

You can use a string length and compare the input.

var str = field1.rawValue

var n = str.length

if(n != 5 || n != 9){

message...

field2.rawValue = ""

}