Hi Molly,
You can use a regular expression as a field validation rule as one option for this as below to let Mendix check this for you.
This only allows the field to be valid if it fits the Abcdef type format with the first character upper case and all other characters lower case.
The alternative is to let the user enter what they like and use a Before Commit event to call a Microflow to correct the text if necessary. You can use the string functions to covert the first character to uppercase and the rest to lowercase, substring, toUpperCase, toLowerCase as one option
https://docs.mendix.com/refguide/string-function-calls
See example below
Is the input text just a single word or more complex?
Regex based validation rule
Before commit Microflow
HI,
I would prefer you to check this https://forum.mendix.com/link/questions/238 post. Hope this gives you an idea for your requirement.
Yesterday, you asked the same question here: https://forum.mendix.com/link/questions/109131
If you are comfortable with Java, then a Java action may be the easiest approach. This the action I use when I need to title case an input.
// This file was generated by Mendix Studio Pro.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
// Special characters, e.g., é, ö, à, etc. are supported in comments.
package robertprice.actions;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;
/**
* Attempt to covert a string to Title Case.
*
* This means the String is iterated over and the first character after a non word letter is capitalised. This should work with diacritics and other languages.
*/
public class ToTitleCase extends CustomJavaAction<java.lang.String>
{
private java.lang.String Input;
public ToTitleCase(IContext context, java.lang.String Input)
{
super(context);
this.Input = Input;
}
@java.lang.Override
public java.lang.String executeAction() throws Exception
{
// BEGIN USER CODE
return toTitleCase(this.Input);
// END USER CODE
}
/**
* Returns a string representation of this action
*/
@java.lang.Override
public java.lang.String toString()
{
return "ToTitleCase";
}
// BEGIN EXTRA CODE
private static String toTitleCase(String str) {
boolean uppercaseNextCharacter = true;
if(str == null || str.isEmpty())
return "";
if(str.length() == 1)
return str.toUpperCase();
//split the string into characters
String[] parts = str.split("");
StringBuilder sb = new StringBuilder( str.length() );
for(String part : parts){
if (uppercaseNextCharacter)
sb.append(part.toUpperCase());
else
sb.append(part.toLowerCase());
if (Character.isLetter(part.charAt(0)))
uppercaseNextCharacter = false;
else
uppercaseNextCharacter = true;
}
return sb.toString();
}
// END EXTRA CODE
}