Hi ,
How can we apply string data validation in the textfield in Appian. I have a requirement in which the first two alpahbets, should be either a or A and the second one will be c or C. In short for a particular string , how can i check the character value at a particular index and apply validation.
Discussion posts and replies are publicly visible
In addition to charat(), you might also check out the function left(); left("aces", 2) would result "ac", which should satisfy your use case. I'll post a more expansive code sample here, just to be thorough:
a!textField( label: "My Text", value: ri!textInput, saveInto: ri!textInput, validations: { if( upper(left(ri!textInput, 2)) = "AC", null(), "Text must begin with the string 'AC' (case insensitive)." ) } )
hi mike , sorry for late reply , what if i want that the input text (string) is of MM/YYYY format , i am using validation on text filed. I have to extract only month and year and save them into db in mm/yyyy format
Why not use an Appian Date field to capture a date type value, then extract the month and year from that? This would keep you from having to use a lot of extra custom validation.
Doing this using text would be possible, but it would be frustrating and complicated. Perhaps less complicated if you have the regex plugin and you're already pretty familiar with how to use regex.
You add to yourself far greater work of avoiding months like 99, 55, AJ, RJ, GG, QQ, $%, **, or years like 1527, 1066, 9999, 4597, or "Spider-Man 2099" or "Steve Jobs' Birthday".
It's so much simpler to just use the component that's already designed to prevent users from inputting anything other than a date.
Could you also use dropdown fields to limit their options? If you provide a dropdown for month and year right next to each other, a validation wouldn't be necessary because you would only display months and years that are valid.
Date field or paired dropdowns work really well. One of the key principals of good UX is to, where possible, make it extremely difficult for the end user to make a mistake.