• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Character count in text field

Character count in text field 15 years 4 months ago #9625

Hi everyone,

I'm looking for some help with creating a custom script that will check whether a text field has a certain number of numeric characters. More or less than the actual number required should invalidate the submission.

Any help greatly appreciated!
The administrator has disabled public write access.

Re:Character count in text field 15 years 4 months ago #9657

  • alexp
  • alexp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 2253
  • Thank you received: 180
Hello,

I am gonna post the script that does this here so others can use it (david added a support request):
<script type="text/javascript">
function validate()
{
if(parseInt(document.getElementById('Card Number').value.length) < 16 || parseInt(document.getElementById('Card Number').value.length) > 16)
{
	alert('Incorrect card number');
	return false;
}
else
	return true;
}
</script>

In the Additional Attributes area of the submit button you will have to place the following trigger:
onclick="return validate();"
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.

Re:Character count in text field 11 years 9 months ago #24921

  • support
  • support's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
This code is 3 years old and this mothod doesn't work for me. Any suggestions how to solve this problem today? I need the user to enter exactly 5 numeric character (ZIP Codes for Germany)s - not less, not more.

How do I do that? I'm not a programmer.

getimo
The administrator has disabled public write access.

Re:Character count in text field 11 years 9 months ago #24923

Hello,

In the case of a Textarea field you will need to add a PHP "Script called on form process" in the Components > RSForm!Pro > Manage Forms > edit your form > Properties > PHP Scripts area (second textarea).

Something like the following should do the trick:
if(strlen($_POST['form']['name_of_your_textarea_field']) > maximum_number_of_characters)
	$invalid[] = RSFormProHelper::getComponentId("name_of_your_textarea_field");
PS: Please remember to replace the the placeholder text with the values relevant to your scenario.

Regards!
Please remember that my responses aren't considered customer support, to receive customer support please submit a new customer support ticket, and we will gladly assist you.

Best Regards,
Cristian Nicolae.
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!