Valid US State Options | XM Community
Skip to main content
Question

Valid US State Options

  • September 25, 2019
  • 3 replies
  • 109 views

I have one field in a text entry question that has "valid US state" as the validation. I need this to be the two-letter abbreviation. Is it possible to do this? I have searched and keep coming up empty. Thanks

3 replies

BruceK
Level 2 ●●
Forum|alt.badge.img+11
  • Level 2 ●●
  • September 27, 2019
If you want to make sure it is a valid two-letter abbreviation, why not make it a drop-down box where they select the abbreviation, instead of entering it as text?

  • Author
  • September 27, 2019
This field is one of 7 in a text entry question. We are collecting contact information and their is a separate field for each item.

Tom_1842
Level 8 ●●●●●●●●
Forum|alt.badge.img+28
  • Level 8 ●●●●●●●●
  • June 14, 2023

2 approaches come to mind. 1 is to use the "valid US state" validation and then limit the amount of characters that can be typed to 2 using JavaScript. The below would work for the 1st Form Field:

jQuery("#"+this.questionId+" input[type=text]").eq(0).attr("maxlength","2");

Another approach would be to use Custom Validation where the 1st Form Field matches the following regex:

[Aa][LlKkRrZz]|[Cc][AaOoTt]|[Dd][CcEe]|[Ff][Ll]|[GgLlPp][Aa]|[HhRr][Ii]|[Ii][DdLlNnAa]|[Kk][SsNn]|[Mm][EeDdAaIiNnSsOoTt]|[Nn][EeVvHhJjMmYyCcDd]|[Oo][HhKkRr]|[Ss][CcDd]|[Tt][NnXx]|[Uu][Tt]|[Vv][TtAa]|[Ww][AaVvIiYy]