Skip to main content
Nintex Community Menu Bar

How do I only allow specific text for a user input field?

  • June 14, 2018
  • 7 replies
  • 212 views

Forum|alt.badge.img+3

I have a single line text control in an item form and I'm having trouble with the exact validation settings to produce the desired result.  I'm new to regex but I've managed to at least set validations to allow all alphanumeric characters and just the dash ( - ) special character.  However, what I would really like is to only allow specific two-letter combinations (i.e. NW, SU), two-digit numbers (1-99) and the dash ( - ) special character.  I've attempted many permutations in regex (scouring the web and these forums for clues) but have had no luck so far.  Any help would be much appreciated and thanks!

7 replies

Forum|alt.badge.img+14
  • Scholar
  • June 14, 2018

Is there a restricted set of allowed two-letters combinations? Or any two-letter combination is allowed? Is there any rule/pattern what combinations are allowed?

Is there any rule/pattern what should/have to be sequence of letters and digits groups and a dash?

Could you some samples of allowed  and not allowed  inputs?


Forum|alt.badge.img+3

There is a set of restricted combinations--AM, SU, NW, MI, and MA (upper and lowercase are permitted)--I'm just unsure of the necessary syntax to declare them in an expression.


Forum|alt.badge.img+14
  • Scholar
  • June 14, 2018

from so far quite vague set of requirements I can recommend eg. following regex expression

^((AM|SU|NW|MI|MA)|(d{2})|(-(?!-)))+$

see some of inputs that it matches (colored) and that not

216632_pastedImage_1.png

to satisfy your requirement of case insensitivity, above regex expression need /i flag to be applied.

assume, you use custom regular expression validation in control's settings. this feature unfortunately doesn't support regex flags.

so you you need to make above regex expression bit more complex

^(([aA][mM]|[sS][uU]|[nN][wW]|[mM][iI]|[mM][aA])|(d{2})|(-(?!-)))+$

216633_pastedImage_2.png

I'm not sure whether this suits you or not.

but until you specify your exact requirements in more details  that's the most you can expect.


Forum|alt.badge.img+3

Apologies for not being more specific.  The alphanumeric combinations are a naming convention for specific actions in the application process for coal mining permits.  The combinations are the letter pairs AM, SU, MI and MA followed by a dash then a two-digit number (i.e. MA-05).  NW uses no number since it represents the first permitting action (new).  There are also occasions which would necessitate using a combination such as NW-AM-05.  Case sensitivity is unnecessary (and makes input easier for the users) since I can just use the ToUpper function to display the values on forms in all caps if need be.  The expression you've written works perfectly based on the requirements I described in my original question.  Requiring only two-digit number combinations after the dash for the letter pairs AM, SU, MI and MA would be the only other validation I would like in the expression--but I understand if you've already devoted enough time to this endeavor.  Thanks again for your contribution!


Forum|alt.badge.img+14
  • Scholar
  • June 19, 2018

I still have some minor doubts, but let's try following

^((NW)|(?(?=NW-)(NW-(AM|SU|MI|MA)-d{2})|(AM|SU|MI|MA)-d{2}))$

216664_pastedImage_2.png


Forum|alt.badge.img+3

Sorry I haven't replied sooner (I wear a lot of hats in our agency).  I put together an amalgamation of both expressions and it works perfectly!!  Thanks so much again for your help!


Forum|alt.badge.img
  • January 10, 2020

Need to accept numbers only with "-" or only numbers. Examples:2233-12 or 1234


@emha wrote:

from so far quite vague set of requirements I can recommend eg. following regex expression

 

^((AM|SU|NW|MI|MA)|(d{2})|(-(?!-)))+$

 

see some of inputs that it matches (colored) and that not

216632_pastedImage_1.png

 

 

to satisfy your requirement of case insensitivity, above regex expression need /i flag to be applied.

assume, you use custom regular expression validation in control's settings. this feature unfortunately doesn't support regex flags.

so you you need to make above regex expression bit more complex

 

^(([aA][mM]|[sS][uU]|[nN][wW]|[mM][iI]|[mM][aA])|(d{2})|(-(?!-)))+$

 

216633_pastedImage_2.png

 

 

I'm not sure whether this suits you or not.

but until you specify your exact requirements in more details  that's the most you can expect.