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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Forcing a Numeric Pattern

Avatar

Level 2

Is it possible to

force a numeric pattern to display a pattern like XXXXX-XXX no matter how many numbers are entered?  I want to lock the field to 8 numeric characters (without using a comb), and a hyphen between the 5th & the sixth.  Currently, my field forces the pattern, but if I put in more than 8 characters, the pattern goes away, and allows a new pattern like this: XXX,XXX,XXX

Is this possible?  If so, please walk me through the process.

Thank you!

0 Replies

Avatar

Level 7

You need to limit the number of characters allowed in the field to 8. You can do this with a script on the change event using javascript.

if(xfa.event.newText > 99999999 || xfa.event.newText < -99999999) { xfa.event.change = "";}

Avatar

Not applicable

if (xfa.event.newText.length > :smiling_face_with_sunglasses:

     xfa.event.change="";

That will work with both text and numeric input. It's also a bit shorter and easy to manipulate.

Kyle

Avatar

Level 2

I tried both of your suggestions, and it didn't quite work the way I need the field to work.  I want to limit the field to 5 characters, hyphen, three characters (zzzzz-zzz), and no more.  Currently, even with your suggested javascript codes, if the user enters more than eight characters, the input mask changes to zzz,zzz,zzz.  I would like to lock the value so no one can enter more than 8 characters, with the mask defined in my second sentence.

Avatar

Level 7

You just need to set an input pattern, like:

num{99999-999}

Avatar

Level 2

When I set the input pattern you suggest,

and enter more than 8 characters (i.e. 111111111), an error pop-up states "NumericField2 Validate failed". When I click the "OK" button on the error pop-up, the field fills with 111,111,111, allowing the entry.  Can the field not lock the entry to my input mask pattern?

Avatar

Level 10

You do not need a validation pattern here because you are checking the input with the script.

Try like this..

Display Pattern:      num{99999-999}

Edit Pattern:           num{99999999}

No Validation Pattern.

In the Change event of the NumericField put the following code..

if (xfa.event.newText.length > :smiling_face_with_sunglasses:
     xfa.event.change="";

Thanks

Srini

Avatar

Level 2

That did it!

I guess I do not understand the difference of the "Display" and Edit" pattern.  I thought you would have the same patten in each.  Also, FormCalc & Javascript are still a bit foreign to me.  Thank you for providing the script.

Avatar

Level 7

Display is what the user sees when they exit the field, Edit is what the user types in.