views:

38

answers:

1

If I have a textarea and I put in a newline, FireFox and IE 7/8 seem to store that as "\n". (i.e. if I do val.match(/\n/) it finds something, but val.match(/\r/) finds nothing) C# of course represents newlines as "\r\n". This leads to problems when we have maximum length restrictions, since every newline is counted as one character in the browser but two on the server.

This must be a problem that others have run into before, so what is the solution? Should I manually count '\n' as two chars in the browser? (Is there a jQuery option that will do this for me?) Should I strip out the '\r' on the server? Either way it seems like I might get into trouble.

+1  A: 

I'd strip/transform it on the server. Its an input issue, so handle the case. Dont do it on the client.

jasper