57
Views
10
Comments
Solved
###### Text Area Line Limit
Question

Hi guys,

So I have a form, and one of the fields is text area for address. This address input can be maximum 4 lines and each line can be no more than 35 characters. I have added validation so that a line cannot exceed 35 characters, however how do I validate against the number of lines entered?

Thanks,

Asha

mvp_badge
MVP
Rank: #114
Solution

Hi Asha,

You can do this by spliting your text with nre line characters and check how many lines were entered in the text area. For this you can use String_Split function from Text extension and split your text with below character which is new line character. I have added image because typing it will change to new line character and you will not be able to see the code.

I hope this will help.

Rank: #46

Hi,

If each line can only have 35 characters and at most you can only have 4 lines, then you only have to count if you have no more than 140 characters in total (35 x 4). I think this will help you :)

Cheers

mvp_badge
MVP
Rank: #74

I'm not sure that's a good idea Nuno :).

I could for example enter 14 lines of 10 characters with that type of validation.

Regards,

Nordin

Rank: #46

I understand your point of view Nordin .. But supposing he already controls the number of characters that have a line ... then he knows to see that the line X1 cannot have more than 35 characters, and the same for X2, X3 and X4.

But I understand your point of view, it depends on how he validated the 35 characters per line.

Asha Vadher, can you give us more information on how you counted the lines?

Rank: #88

Asha Vadher wrote:

Hi guys,

So I have a form, and one of the fields is text area for address. This address input can be maximum 4 lines and each line can be no more than 35 characters. I have added validation so that a line cannot exceed 35 characters, however how do I validate against the number of lines entered?

Thanks,

Asha

If you can check if the line doesn't exceed 35 characters then surely counting the number of times you performed this checked isn't that hard? Just add a counter or something.

But as a small side note. Isn't 35 characters a bit small for an address field? If you live in a nice apartment building with some creative addressing then you can easily run out of space.

edit: Sorry, I seems I'm late to the party. That should teach me not to reply to a thread of which I had the tab open for a long time... :(

mvp_badge
MVP
Rank: #114

Hi Asha,

I would suggest you to count the characters of each line after spliting them using String_Split instead of counting using onkeyup. Because with onkeyup there can be various cases which you have to handle like backspace, delete, select and delete etc and this is not good for client side performance also.