0

I am using Joomla 2.5 user registration form. I added manually one more fields for user phone number, and I am doing server side validation.

Code is : registration.xml

<form
      addrulepath="/administrator/components/com_user/models/rules"
      >
     <field 
     name="pnumber" 
     type="text"
    description="Enter your valid Number"
    label="Phone number:"
    required="true"
    size="30"
    hint="EX:080-12345678"
    class="inputbox validate-mobile"

    />

and I have created validation file in administrator\components\com_users\models\rules\mobile.php

code is :

    <?php


     defined('JPATH_BASE') or die;

     jimport('joomla.form.formrule');


     class JFormRuleMobile extends JFormRule
     {


     public function mobile(& $element, $value, $group = null, & $input = null, & $form = null)
     {
     return preg_match("/^\+{0,1}[0-9]{6,14}$/",$value);
     }
  }

  ?>

When I submit the form "Validation Rule missing: mobile" error is coming. What is the problem?

4
  • Is this a completely manual field you have added or are you doing it through the Joomla profile plugin?
    – Lodder
    Jan 22, 2015 at 10:03
  • manual field only . adding in registration.xml file Jan 22, 2015 at 10:04
  • @Lodder any solution ? Jan 22, 2015 at 10:23
  • please check i have modified my question . Jan 22, 2015 at 11:55

2 Answers 2

1

Ufff ...... I got the Answer .

I just used joomla inbuilt rule called "tel"

problem solved . thank you every one :)

1
  • Ahh fair enough. Would have recommended this, but thought you required something more specific. Don't forget to accept your answer when you can ;)
    – Lodder
    Jan 22, 2015 at 14:58
0

Try the following:

Add validate="mobile" to your <field> in the XML file

Then change the mobile.php to the following:

<?php

defined('JPATH_BASE') or die;
jimport('joomla.form.formrule');

class JFormRuleMobile extends JFormRule {

    protected $regex = '^\+?\d{6,14}$';

}

Let me know what the outcome of this is.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.