1

i am using Joomla 2.5 user registration form . manually i added one more field 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"
        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 . where i am doing mistakes

Nayana
  • 747
  • 8
  • 27
  • possible duplicate of [Validate phone number in joomla 2.5](http://stackoverflow.com/questions/12947785/validate-phone-number-in-joomla-2-5) – Alessandro Da Rugna Jan 22 '15 at 10:37
  • No ,,that question Not helped at all. – Nayana Jan 22 '15 at 10:40
  • when and where did you called that function to validate? – Toretto Jan 22 '15 at 12:12
  • do not add/edit core files its not recommended, You can create Plugins Joomla already comes with sample profile plugin check the code and catch the proper [plugin](https://docs.joomla.org/Plugin/Events) events ! – Jobin Jan 22 '15 at 12:17

2 Answers2

1

its very simple ...

just use joomla inbuilt rule called "tel" .its very good for validate the phone number

more info joomla document about this

mani
  • 436
  • 3
  • 13
0

You need to enable the behaviour of validate on your form. Add form-validate class to your form as well. you have different classes:-

  1. required
  2. validate-username
  3. validate-password
  4. validate-numeric
  5. validate-email
  6. validate-[custom] -> custom defined Use this link for Joomla

Or you can easily validate the form using jQuery or HTML's required attribte and pattern attribute.