Drop down field validation using a regular expression.

Don Einan asked on August 17, 2018 18:15

I'm new to learning about using macros and K# to create expressions. I'm sure for some of you out there this will be child's play. I have a Kentico form with a drop down list where the first option says "(please select one)." I tried to set up a validation expression that checks to see if the user has selected something from the list by comparing the field contents to the string "(please select one)." The logic is that if it does equal that string, the user has not chosen from the list so produce the error message.

I've tried several ways of doing the expression that seem like they should work but they don't. Even when the user selects something it won't allow them to submit. This is the expression I came up with. I'd appreciate any suggestions people might have as to how to get the validation to work. {$!Product.Equals("(please select one)")$}

Recent Answers


Arun Kumar answered on August 17, 2018 18:36 (last edited on August 17, 2018 18:38)

Seems like this already discussed, check this post. You can use the the built-in validation with some fixed value for first option like 0 or 1 and then use this value to compare in built in validation rule like minimum length or something like that.

0 votesVote for this answer Mark as a Correct answer

Dragoljub Ilic answered on August 18, 2018 14:47

Hi Don,

If you are using default Kentico Forms, you can simply select Dropdown form control and make it required. Then, in Datasource add something like this:

;(please select one)
1;value 1
2;value 2
3;value 3

NOTE: That on first item (before ';') you don't have any value, which means that default value for first item will be empty, and because you marked dropdown as 'Required', that will trigger validation for the form and won't allow you to submit it.

Best regards, Dragoljub

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.