Active Agenda Community Forum Index Active Agenda Community
"Controlling Loss, Not Minds, Methods, or Markets"
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Regular expression to validate the entry

 
Post new topic   Reply to topic    Active Agenda Community Forum Index -> New Feature Ideas
View previous topic :: View next topic  
Author Message
JWach



Joined: 17 Sep 2007
Posts: 65

PostPosted: Wed Nov 28, 2007 4:33 am    Post subject: Regular expression to validate the entry Reply with quote

Hi,

Edit fields should have the possibility to specify a regular expression to validate the entry. If the entry doesn’t match the pattern, the record is not entered into the database and an error is displayed. The regular expression should be specified as an XML attribute according to the PHP implementation (http://pl2.php.net/manual/en/ref.pcre.php ).

Cheers,
JWach
_________________
http://xdash.jabberstudio.org
http://fastforward.sourceforge.net
---------------------------
Back to top
View user's profile Send private message
mattias
Site Admin


Joined: 07 Mar 2005
Posts: 204

PostPosted: Wed Nov 28, 2007 8:02 am    Post subject: Reply with quote

Hi,

Sure, why not? Perhaps by extending the "validate" attribute with a syntax for regular expressions.

I also wish for javascript validation so that users can correct problems before submitting.

Cheers,

Mattias
Back to top
View user's profile Send private message
JWach



Joined: 17 Sep 2007
Posts: 65

PostPosted: Thu Nov 29, 2007 4:45 am    Post subject: Reply with quote

Hi,

@ The first part is easy to fulfill. Very Happy I inserted in web_util.php after line 239
Code:
} elseif ( preg_match ( '/^\s*regexm:\s*/' , $validationString ) ) {
       
        $validationString = preg_replace ( '/^\s*regexm:\s*/' , '' , $validationString  );
       
        // RegEx: http://www.php.net/manual/en/reference.pcre.pattern.syntax.php
        if( preg_match ( $validationString, $value ) ) {           
            return '';           
        } else {           
            return sprintf(gettext("The field '%s' must match pattern: '%s'."), $shortPhrase, $validationString)."\n";                   
        } 

It seems to work so far.

@ It should be used as
Code:
 <TableField name="XXX" type="varchar(10)" validate="regexm: /patern/"/>
[1] regexm is an abreviation for Regular Expresion Match
[2] patern syntax should be compliant with http://www.php.net/manual/en/reference.pcre.pattern.syntax.php

Cheers,
JWach
_________________
http://xdash.jabberstudio.org
http://fastforward.sourceforge.net
---------------------------
Back to top
View user's profile Send private message
mattias
Site Admin


Joined: 07 Mar 2005
Posts: 204

PostPosted: Fri Nov 30, 2007 11:42 am    Post subject: Reply with quote

Hi Jerzy,

Thanks for the suggestion, a really good one! I'll try it out.

My only immediate addition to this would be to mention that this owuld also require some way to enter a custom validation error message. "The value you entered does not match the regular expression for this field" would not help the user understand what they need to change. If it can say (for instance) "The value you entered is not a valid Polish telephone number", or "You must enter 16 digits and 12 letters", that would be more helpful.

I suppose there could be a new attribute for this. Or, it could be crammed together with the validate attribute. Neither would be particularly elegant, I'm afraid. Other ideas?

Cheers,

Mattias
Back to top
View user's profile Send private message
JWach



Joined: 17 Sep 2007
Posts: 65

PostPosted: Fri Nov 30, 2007 10:33 pm    Post subject: Reply with quote

Hi,

I expanded the idea further to the abilty to reformat the input. I send you the files on Monday by email (I let my notebook in the office).

Cheers,
JWach
_________________
http://xdash.jabberstudio.org
http://fastforward.sourceforge.net
---------------------------
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Active Agenda Community Forum Index -> New Feature Ideas All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group