Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing hard return in a text area with regexp

Status
Not open for further replies.

bbhqhmc

Programmer
Nov 12, 2003
5
US
I have a textarea field in a form. I want to remove any hard returns the user may have entered before I pass the field on to my CGI program. The wrap parameter does not seem to make any difference to the value of the textarea data. So I figure you have to do with with a validation function. Fair enough.

Certainly I am not the only person who has tried to do this.

Apparently, you have to look for both a return - \r - and a new line - \r

But, according to Danny Goodman, Windows, Unix, and Macintosh handle a hard return differently. He suggests using the escape method to return the equivalent %OD or &OA. But then I have to get get rid of the %OD or %OA. I do not see that that helps, except that it does make the field all one line.

I can create a loop, scanning each character for a \n or \r and replacing either with a space. That should work in any platform.

But there must be a faster way to do it with regexp that will work in any platform. But I can find no source that references this, with or without using regexp.

This should be a basic issue related to forms processing.
Am I really the only person who has tried to do this?

Thanks.

 
bbhqhmc,

Here's a tool that might help you with some ideas,
2nd post from the bottom...

thread216-702227 [/code]

Let us know if that doesn't help...



2b||!2b
 
Thanks. It looks like it is the replace method that is doing the heavy lifting there. But it does work. I'll just have to beat my head some more to understand what RegExp is doing. Thanks.

BTW - In my testing, I was looking for \n\r - I guess I should have been looking for \r\n

What a world, what a world!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top