• 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: Custom Validate a field for a specific pattern?

Custom Validate a field for a specific pattern? 10 years 1 month ago #30599

  • djaber2000
  • djaber2000's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 33
  • Thank you received: 3
I would like to validate a field that will always start with one Alpha character, followed by 6 numbers.

Like: A123456


I have been researching the forum for custom validations using Regex patterns, and also preg_match. I found a script, and I am trying to make it fit my required validation above, but cant get it to work when added to validation.php. Am I doing this correctly?
public static function customValueField($value)
	{
		if (preg_match("/^[a-zA-Z] [0-9]{7}$/",$value) {
		return true;
		}
		return false;
	}
Last Edit: 10 years 1 month ago by djaber2000.
The administrator has disabled public write access.

Custom Validate a field for a specific pattern? 10 years 1 month ago #30608

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
You don't need to use a custom validation rule for this. Easiest solution would be to go to the Form and edit the field you wish to validate with this expression.

Select REGEX as Validation Rule and insert this:
/^[a-zA-Z][0-9]{6}$/

This should work.

You can test other REGEX expressions here: http://www.regexr.com/

More information on textboxes can be found here:
https://www.rsjoomla.com/support/documentation/view-article/826-textbox.html
My help is not official customer support. To receive your support, submit a ticket by clicking here
Last Edit: 10 years 1 month ago by cosmin.cristea.
The administrator has disabled public write access.
The following user(s) said Thank You: djaber2000

Custom Validate a field for a specific pattern? 10 years 1 month ago #30630

  • djaber2000
  • djaber2000's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 33
  • Thank you received: 3
Thank you Cosmin. That was exactly it. Instead of trying to add a custom validation, I just chose REGEX like you advised, added the expression, and it works great!
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!