+ Start a Discussion
samarsamar 

Remove newline in validation rule

Hi Everyone,

I have a requirement which required to remove newline character before validating the value in textarea. But formula TRIM function only remove white space and tabs unlike apex trim() function. Also I am unable to use SUBSTITILE as \n or \r is not identified in validation rule formula. Please kindly suggest me some way to identify or remove newline character.

 

Regards,

Samarjit

ritika@developerforceritika@developerforce

Hi,

 

I think you should be able to use SUBSTITUTE method. This replaces all occurences of a particular string with another string.

 

Syntax - SUBSTITUTE(text, old_text, new_text)

 

More information - https://login.salesforce.com/help/doc/en/customize_functions.htm#SUBSTITUTE

 

Hope this helps.

samarsamar

Hi Ritika,

Thanks for your reply.

I have already used SUBSTITUE function, but I am stucked there only because it can't identify the newline characters so that I can replace them. I tried SUBSTITUTE(textAreaField,"\n","") even used \\n,\\\n but in vain. Even TRIM() function can't remove  preceding and succeeding blank newlines.

 

 

dRidRi

Hi, you'll need to use REGEX in order to identify the new line character as this is the only function that allows the use of "external expressions".

 

With REGEX you can use regular expression syntax based on Java: http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html

 

I hope that with this you can use some expressions like \n or other defined in the Java document linked above.

Good luck with it.

samarsamar

Hi dRi,

First off thanks for you reply but how can I use REGEX to replace newline as REGEX can only help me to identify newline as REGEX returns boolean only. Are your talking about to use regular expression in SUBSTITUE function to identify newline?

 

Regards,

Samar