In the expense Item name field I don't want that the user can put there numbers. If done, It should return error as "don't put numbers in the text field."
Discussion posts and replies are publicly visible
Hi Vikash,
I suggest you check the following thread in which some possible solutions for your problem are discussed (https://community.appian.com/discussions/f/rules/4544/we-have-text-fields-that-we-need-to-validate-are-numbers-for-example-if-the-v).
Once you have the approach that you believe works best for your use case, you will need to associate that expression rule to the validations property of your Text component.
As i understand, this topic solves the issue to just have numbers. vikashk wants the other way around, that no numbers should be possible.
hi vikashk,
a!textfield() has a validation attribute called "validations".
checkhttps://docs.appian.com/suite/help/18.4/Text_Component.html
you can use a if clause here. Example of several ways to solve it:
validations: if( contains( a!forEach( items: enumerate(10), expression: search(tostring(fv!item),local!saveInto,1)=0 ), false ), "dont put numbers", {} )
You're right Richard. Thank you for bringing that up.
With that taken into consideration, vikashk739 you can always use a regular expression to control the behavior you want (you'll need the Regular Expression Functions plugin - community.appian.com/.../regular-expression-functions -). Also check Richard's suggestion below using an enumerate.
a!textField( label: "Expense Item", labelPosition: "ABOVE", value:ri!text, saveInto: ri!text, refreshAfter: "UNFOCUS", validations: if(regexmatch("^[a-zA-Z ]*$",ri!text),null,"No Numbers Please") )
Richard's suggestion should do the trick! I also like to use the cleanwith() function to identify any uses of numbers in a text string:
a!textField( label: "Text", saveInto: ri!text, value: ri!text, validations: { if( isnull( cleanwith( ri!text, "1234567890" ) ), null, "Please provide only letters" ) } )
Hi peter,
thank you for your valuable response.
I was originally on the same path with cleanwith. :) I dismissed it because it filteres inserted values and asks, if something is left. Works fine for pure inserted numbers. does this work for alphanumeric ?
haven't tested it. Thank you for your input.
Yep, it will work for alphanumeric too! For example, if the text string I gave was "abc123", the cleanwith() example I showed above would return "123". The reason I like this function is that you don't have to do any looping - just provide the text you want to look for and it will identify if any of them are present.
You have the option of either cleanwith or stripwith.
One whitelists, the other blacklists.
Blacklist means you have a list of characters that are NOT allowed, in your case your blacklist would be {1,2,3,4,5,6,7,8,9,10}. The problem is that you allow EVERYTHING not in the blacklist, so you have to enumerate everything in the universe you don't want to allow. People can still input A, or Ç, or Ц, or ㅂ, or き or or ️ or or (╯°□°)╯︵ ┻━┻ into your text field. There's a world absolutely full of what you don't want.
Whitelisting is much safer; it's the exact opposite, a list of all the characters that ARE allowed, in your specifically worded case only {abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ} You DISALLOW everything not in the whitelist. It looks like a lot, but now your users can really use "only letters" and all the examples above AND numbers will all fail to be input. Whitelisting is much safer because it accounts for everything you thought of and everything you didn't think of too.
Just for fun, add (╯°□°)╯︵ ┻━┻ to the whitelist also.
Yeah this is way better than my suggestion above