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

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.


Solution

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

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

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?

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... :(

Nuno Miguel Verdasca wrote:

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?

I see now Nuno. I didn't catch the part were she could already validate that a line has 35 characters :).


Nuno Miguel Verdasca wrote:

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?

Hi Nuno,

I just used an onkeyup to check the number of characters for a line.


Vincent Koning wrote:

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... :(

Hi Vincent,

Ha thanks for the reply. Yeah the 35 character limit is usual for an address line, but thats the requirement!


Nikhil Gaur wrote:

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.

Hi Nikhil,

This is exactly what I needed! 

Thank you very much!


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.