20
Views
10
Comments
Solved
How to Remove just "Enter" in a mandatory text area?
Application Type
Traditional Web, Reactive

Hi all..

I have difficultly removing the character "Enter" when my text area is mandatory, and the user insert just a "Enter" on this input.

I already try use the function "Trim()", but just remove "spaces".

I want to remove the "Enter" when the user does not insert any characters.

If user insert any other character, I don't want remove the "Enter", because the user can insert a line break text .

Thank you if someone gets the solution.

Rank: #68
Solution

Hi Dairon,


You're right! Indeed multiple enters were not being taken into account.

Can you try again with this pattern (\r\n)*\r?\n$   please?

So basically, the pattern

(\r\n)*  - this part covers any number of enters (carriage return and new line), from 0 to any sequence of enters

\r?\n$ - and this part ensures it finishes with an enter (due to the $ symbol), with or without a carriage return before (due to ? symbol)


OML in attachment.


Regards,
João

AppTesteREGEX.oml

Rank: #68
Solution

Hi Dairon,


You can use Regex to remove the enters, here is an example:


As you see it removed the Enter.

If you have worked with Regex before, you just need to replace the \n pattern by nothing.

In any case, you can test your patterns on the Try Now option of the Regex How To Component or download it to learn how to implement both on server side and client side.


Hope it helps.


Kind regards,
João

Thank you João, I understand your answer.

But, I want to remove "Enter" just user doesn't insert any characters.

If user insert any character, I don't want to remove any "Enter".

Rank: #68

Hi Dairon,

You can try to remove the enters at the last of the string, using pattern \n$.

In this way, if user just wrote enters, you will get an empty string that you can validate if it is empty.

If the user wrotes something, you won't have an empty string and the validation will pass.


Regards,
João

Thank You João, I'll try it later and come back to talk if it worked

Hi John, it didn't work, I think I'm doing something wrong

I have attached the .oml file

App Test REGEX

when I enter only "enter", it passes the validation, and I don't expect that to happen, I need to bring an error when I enter only "Enter"


AppTesteREGEX.oml

Rank: #68

Hi Dairon,


After checking I noticed two things were missing:

  • The MultiLine property value to True;
  • And the pattern should also take into account the carriage return, so I changed the pattern to \r?\n$|\r$


The OML follows in attachment.


Regards,
João

AppTesteREGEX.oml

Great, now it works.

Your help solved the problem.

Thank you very much!

Hi João, I'm here again, sorry

 I found a fail

When I enter 1 "Enter" without other characters, it worked

But when I enter 2 or more "Enters" without other characters, it doesn't work

Rank: #68
Solution

Hi Dairon,


You're right! Indeed multiple enters were not being taken into account.

Can you try again with this pattern (\r\n)*\r?\n$   please?

So basically, the pattern

(\r\n)*  - this part covers any number of enters (carriage return and new line), from 0 to any sequence of enters

\r?\n$ - and this part ensures it finishes with an enter (due to the $ symbol), with or without a carriage return before (due to ? symbol)


OML in attachment.


Regards,
João

AppTesteREGEX.oml

Yeahhh, now it worked..

Thank you very much