 |
Active Agenda Community "Controlling Loss, Not Minds, Methods, or Markets"
|
| View previous topic :: View next topic |
| Author |
Message |
JWach
Joined: 17 Sep 2007 Posts: 65
|
Posted: Wed Nov 28, 2007 4:33 am Post subject: Regular expression to validate the entry |
|
|
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 |
|
 |
mattias Site Admin
Joined: 07 Mar 2005 Posts: 204
|
Posted: Wed Nov 28, 2007 8:02 am Post subject: |
|
|
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 |
|
 |
JWach
Joined: 17 Sep 2007 Posts: 65
|
Posted: Thu Nov 29, 2007 4:45 am Post subject: |
|
|
Hi,
@ The first part is easy to fulfill. 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 |
|
 |
mattias Site Admin
Joined: 07 Mar 2005 Posts: 204
|
Posted: Fri Nov 30, 2007 11:42 am Post subject: |
|
|
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 |
|
 |
JWach
Joined: 17 Sep 2007 Posts: 65
|
|
| Back to top |
|
 |
|
|
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
|