You are viewing limited content. For full access, please sign in.

Question

Question

Forms Address Block Limit Zip to 5 Digits

asked on November 30, 2020

Looking for a little input.  I am using an address block in Forms and I want to not only set the limit of the Zip Code to 5 but I want to limit the input to digits.

 

I can set the max length to 5 characters with $(".Postal").attr("maxlength", 5); in the JavaScript.

 

I can limit it to numbers using $(".Postal").attr({"type", "number"); BUT that puts up and down arrows at the end of the field input and I don't like that.

 

I have been playing around with $(".Postal").attr("pattern", "\d{5})"); and multiple variations such as [0-9] but [0-9] always tells me it is invalid input no matter what I put in the field.  And other variations I have tried always break the rest of the javascript for the state and county fields.

 

Does anyone out there have a simple way to limit the Zip in an address block to 5 digits?

 

Thanks.

1 0

Answer

SELECTED ANSWER
replied on December 1, 2020 Show version history

Try:

$(".Postal").attr("pattern", "\\d{5}");

2 0

Replies

replied on December 1, 2020

Thanks Aaron,

 

I tried various options with \\d and options with {5} but guess I never got the right combination together.  I have your suggestion a try and it worked great!

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.