Welcome, Guest
Username: Password: Remember me

TOPIC: Regular Expression front-end

Regular Expression front-end 20 Dec 2012 15:56 #6213

  • blue-canoe
  • blue-canoe's Avatar
  • Offline
  • Senior Member
  • Posts: 57
  • Thank you received: 16
  • Karma: 7
Hello all,

I am struggling with something and not sure what I am doing wrong. I have a front-end view which has a form. This does not use an .XML definition for a form, but it is generated dynamically. (As there is quite a bit of custom processing in there). Now I have a simple input field and I want to attach a regular expression validation to it, but cannot get it to work. The field looks something like this:
<?php
            echo JDom::_('html.form.input', array(
                'dataObject' => $this->item,
                'dataKey' => 'my_field',
                'required' => true,
                'validatorHandler' => 'validate[required,custom[my_rule]', 
                'validatorRegex' => "/^[a-zA-Z0-9._-]+(\+[a-zA-Z0-9._-]+)*@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/"
            ));
 ?>    

That is all I did, I did not create any form rule yet for the server side validation, just want to test the front-end validation. (Also don't know how to add the custom rules to my view as I don't have a form object).

Note: I just used a email validation here for testing as I am sure my field will fail that. When it works a proper regular expression will be defined.

What am I missing here? The jquery validation engine does add the rule to the page, but no error is generated on leaving the field.

Any hint is welcome as I am sure I am overlooking something.

Many thanks,

Misha
The administrator has disabled public write access.

Re: Regular Expression front-end 20 Dec 2012 16:23 #6214

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi Misha,

First thing I can see that might be causing an issue is that the Regex itself does not need the slashes added like; '/' ...regex... '/'. The second is to avoid underscores in the handlers - only use lowercase letters and digits.

Other than that, other than that, I guess try adding the custom rule (file) mimicking the structure/properties of another rule file although, I'm not convinced that this will work as I'm pretty sure that the rules classes are only used for PHP validation.

Why aren't you using JForms to handle this? Version 1.5 cook?

Anyway, hope this helps,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Regular Expression front-end 21 Dec 2012 06:16 #6215

  • blue-canoe
  • blue-canoe's Avatar
  • Offline
  • Senior Member
  • Posts: 57
  • Thank you received: 16
  • Karma: 7
Hi Gez,

Thanks for your reply. However I did figure it out last night. BTW I am using Cook 2.0.
I was not using the correct variables. The following works for me:
<?php
            echo JDom::_('html.form.input', array(
                'dataObject' => $this->item,
                'dataKey' => 'my_field',
                'required' => true,
                'domClass' => 'validate[required,custom[my_rule]]',
                'validatorHandler' => 'my_rule',
                'validatorRegex' => "/^[0-9+]{1,3}$/"
            ));
            ?>      

Cheers,

Misha
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy

Re: Regular Expression front-end 26 Dec 2012 09:28 #6275

  • g1smd
  • g1smd's Avatar
  • Offline
  • Junior Member
  • RegEx fiend!
  • Posts: 31
  • Thank you received: 26
  • Karma: 6
[0-9+](1,3}

Just to be clear you want to be able to match '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' and '+' here between 1 and 3 times,

e.g. 1, 10, 12, 123, 234, 012, 001, 000, +1, 7+, +45, 77+, 1+2, ++3, 3++, +5+, +, ++, +0, 0+, 00+, ++0, 0+0, +0+, +++, etc.
Online since 1996.
Last Edit: 28 Dec 2012 08:42 by g1smd.
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy
Time to create page: 0.068 seconds

Get Started