Trim special characters except '/'

Hello guys,

I have a requirement where user can enter 0-9, a-z, A-Z, / but when user enters other special characters it should get removed.

Sample:

1234acv → 1234acv

1234/ → 1234/

1234@ → 1234

1234!@ad → 1234ad

@ChakilamG You need to write an Edit Validate and embed it in the property itself.

The code should have a replace function like this, which will automatically replace the non-alphanumeric characters:

input.replaceAll("[^a-zA-Z]+","");

Hi @ChakilamG,

  1. Create a function similar to removeSpecialChars and add below code in that.

    StringBuffer OutputString = new StringBuffer(aInput);
    for (int i = 0; i < OutputString.length(); i++) {
    	if ((!Character.isUnicodeIdentifierPart(OutputString.charAt(i))) && ((OutputString.charAt(i)!='/'))) {
    		OutputString.setCharAt(i, '_');
    	}
    }
    return OutputString.toString();
    
  2. This function will take input string and replaces special characters except ‘/’ with _

  3. In your DT activity have function like this @replaceAll(@removeSpecialChars1(String),‘_’,‘’)

Thanks,

Vinay

Note:

  • If you want to change the string as soon as user enters the text in a section you will need to create edit input rule.
  • See if you can achieve it through a regex

@ChakilamG

  • Create a edit validate rule and place below code in that
StringBuffer OutputString = new StringBuffer(theValue);
for (int i = 0; i < OutputString.length(); i++) {
	if ((!Character.isUnicodeIdentifierPart(OutputString.charAt(i))) && ((OutputString.charAt(i)!='/'))) {
		OutputString.setCharAt(i, '_');
	}
}
String data=OutputString.toString();
data = data.replaceAll("_", "");
theValue=data.toString();
  • Use post value action in the section for the text control

Thanks,

Vinay