• 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 Validation

Custom Validation 15 years 10 months ago #7645

  • Coldice
  • Coldice's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 8
I have tried to add the validation to the "validation.php" but it not works why?
Do I need to do something more?

Thanks.

PS: I want the PHONE-Validation. So if you could make it for me that would be good because I don't think my regex code worked.
The administrator has disabled public write access.

Re:Custom Validation 15 years 10 months ago #7653

  • bogdanc
  • bogdanc's Avatar
  • OFFLINE
  • Moderator
  • Posts: 669
  • Thank you received: 11
Hello,

You can refer to the following article where you can find a function for telephone validation:

http://www.rsjoomla.com/customer-support/forum/37-rsform-pro/6470-need-an-input-mask-for-phone-number-help.html

Regards!
The administrator has disabled public write access.

Re:Custom Validation 15 years 10 months ago #7662

  • Coldice
  • Coldice's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 8
Hi!
function phone($phone)
{
if( $phone=='' ) return true;
if(eregi('^((?[2-9]{1}[0-9]{2})?|[0-9]{3,3}[-. ]?)[ ]?[0-9]{3,3}[-. ]?[0-9]{4,4}$', $phone ))
return true;
else
return false;
}

I try this code. But should I change $phone with $param?
The administrator has disabled public write access.

Re:Custom Validation 15 years 10 months ago #7665

  • bogdanc
  • bogdanc's Avatar
  • OFFLINE
  • Moderator
  • Posts: 669
  • Thank you received: 11
Hello,

You can use the code as it is. Just follow the steps in this article:

http://www.rsjoomla.com/customer-support/documentations/32-customizing-rsform-pro/75-custom-validation-rules.html

The new function being "function phone".

Regards!
The administrator has disabled public write access.

Re:Custom Validation 15 years 10 months ago #7668

  • Coldice
  • Coldice's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 8
Thanks, but how should the regex code look like if I want phone number like this:
12345678 - 8 numbers??

EDIT:
The code doesn't work, can you please make the code work for me with 8 numbers like above?

The name of the phone field is: Mobiltelefon
Last Edit: 15 years 10 months ago by Coldice.
The administrator has disabled public write access.

Re:Custom Validation 15 years 10 months ago #7678

  • bogdanc
  • bogdanc's Avatar
  • OFFLINE
  • Moderator
  • Posts: 669
  • Thank you received: 11
Hello,

Here is the correct validation code for a telephone number with 8 numbers:
function phone($phone)
	{
		if($phone=='' || !numeric($phone) || (strlen($phone)!=8)) return false;
		if(eregi('^\([0-9]{3}\) [0-9]{3}-[0-9]{4}$', $phone ))
		return false;
		else
		return true;
	}

It doesn't matter what the name of the field is. Note this is a validation rule so the name of the function will appear in the "Validation Rule" drop down.

Also if anyone else will want to use this function, but with other telephone number length (or without number length limit) please change this line:
if($phone=='' || !numeric($phone) || (strlen($phone)!=8)) return false;

To:
if($phone=='' || !numeric($phone)) return false;

Or just change the limit from 8 to what number would you want.

Regards!
Last Edit: 15 years 10 months ago by bogdanc.
The administrator has disabled public write access.

Re:Custom Validation 15 years 10 months ago #7685

  • Coldice
  • Coldice's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 8
Thanks.
But that's for US number. I'm from Norway and we have number like this:
12345678

So how should the regex be like?
Should it be:
if(eregi('^[0-9]{3}-[0-9]{3}-[0-9]{2}$', $phone ))

For number like this:
123-456-78 ??

EDIT:
Doesn't work at all.
Last Edit: 15 years 10 months ago by Coldice.
The administrator has disabled public write access.

Re:Custom Validation 15 years 10 months ago #7699

  • bogdanc
  • bogdanc's Avatar
  • OFFLINE
  • Moderator
  • Posts: 669
  • Thank you received: 11
Hello,

Use this script for numbers like: 123-456-78
function phone($phone)
	{
		list($number1,$number2,$number3)=split("-",$phone,3);
		if($phone=='' || strlen($phone)!=10 || !(is_numeric($number1)) || !(is_numeric($number2)) || !(is_numeric($number3)) || strlen($number3)!=2) return false;
		if(ereg('^([0-9]{4})-([0-9]{4})-([0-9]{3})$', $phone))
		return false;
		else
		return true;
	}

This script can be customized for all kinds of Telephone Numbers.

Regards!
The administrator has disabled public write access.

Re:Custom Validation 14 years 3 months ago #12427

  • KevenM
  • KevenM's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 14
Where would I install this script? Tried putting it in the scripts section (on load, and on process), but neither worked.

Also, with this script in place, what do we set the standard validation rule to?
The administrator has disabled public write access.

Re:Custom Validation 7 years 3 months ago #37792

  • DiGwork
  • DiGwork's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 33
I would like my number format to be like this in international phone number format:
+27 82 123 4567
With spaces in between and not "-"

Could someone please assist me with the correct script to do this?
Last Edit: 7 years 3 months ago by DiGwork.
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!