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?

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

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

I just used joomla inbuilt rule called "tel"

problem solved . thank you every one :)

  • 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 '15 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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