Hi Guys - Today I was working on a small issue where I had to add some client side validation.
The fix was to add limit to the number of chars in a text area. The fix is as easy as adding 'maxlength=n' attribute.
But this can be circumvented easily in the client side. So what ?
In the server side, are we going to throw an error and raise an exception that the text is too long ?
Well another way is to truncate this text.
In ruby, simply do this -
This will simply truncate the text
Thanks
The fix was to add limit to the number of chars in a text area. The fix is as easy as adding 'maxlength=n' attribute.
But this can be circumvented easily in the client side. So what ?
In the server side, are we going to throw an error and raise an exception that the text is too long ?
Well another way is to truncate this text.
In ruby, simply do this -
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MaxLength = N | |
valid_string = some_long_text[0,N] if some_long_text.length > N |
This will simply truncate the text
Thanks
No comments:
Post a Comment