ok,
worked faster than I expected. But I only have a windows machine and with this
code, preg_match gives back a internal error. I think this is related to my
machine, so could you please test that on your side? Should work out of the
box, if 'Zend/Loader.php' is in your path:
<?php
require_once "Zend/Loader.php";
Zend_Loader::registerAutoload();
$form = new Zend_Form;
$form->setMethod("post");
$regex = new Zend_Form_Element_Text('regex');
$regex->setLabel("Try here:");
$regex->addValidator(new Zend_Validate_Regex("^[\p{L}\.\-_ 0-9]+$"));
$form->addElement($regex);
$form->setView(new Zend_View());
echo $form;
try {
if ($_POST) {
if (!$form->isValid($_POST)) {
echo "Not Supported";
} else {
echo "Supported";
}
}
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
?>
Regards
Matthias
-------- Original-Nachricht --------
> Datum: Fri, 15 Aug 2008 20:47:11 +0200
> Von: "Matthias Coy" <[EMAIL PROTECTED]>
> An: Bruno Friedmann <[EMAIL PROTECTED]>
> CC: [email protected]
> Betreff: Re: [fw-general] Zend_Validate regex way to soluce ?
> ok,
>
> I don't have a running Zend-Framework here, but I've downloaded the code
> and the Zend_Validate_Regex is using preg_match, so that SHOULD work ... why
> it doesn't in your case, that's out of my knowledge. I will try to set up
> a running minimal ZF to create a use case, but I have also some work to do
> :)
>
> Regards
> Matthias
> -------- Original-Nachricht --------
> > Datum: Fri, 15 Aug 2008 20:11:13 +0200
> > Von: Bruno Friedmann <[EMAIL PROTECTED]>
> > An:
> > CC: [email protected]
> > Betreff: Re: [fw-general] Zend_Validate regex way to soluce ?
>
> > Thank you Matthias, I've try this and I just surprise about
> > in the script it work as expected ... (no doubt about :-)
> >
> > But when use with Zend_Form (My description of Form are in .ini file )
> > like this
> > user.elements.userlogin.options.validators.regex.validator = "regex"
> > user.elements.userlogin.options.validators.regex.options.pattern =
> > "/^[\p{L}\.\-_ 0-9]+$/ui"
> > or
> > user.elements.userlogin.options.validators.regex.options.pattern =
> > "/^[\p{L}\.\-_ 0-9]+$/"
> >
> > It just accept anything ! :-(((
> >
> > Just annoying ...
> >
> > PS : I hate regex power :-)
> >
> > Matthias Coy wrote:
> > > Hi,
> > >
> > > ok, I missed the ^ and $. So here is a working example:
> > >
> > > <?php
> > > header('Content-Type: text/html; charset="UTF-8"',true);
> > > $input = array ("Clément", "Marius_Glad", "Micky.128",
> "Some!thing",
> > "Real[Name]", "Zut^Truc");
> > >
> > > foreach($input as $entry) {
> > > echo $entry;
> > > echo "<br />";
> > > if (preg_match('/^[\p{L}\.\-_ 0-9]+$/', trim($entry))) {
> > > echo "\tSupported";
> > > } else {
> > > echo "\tNot Supported";
> > > }
> > > echo "<br />";
> > > echo "<br />";
> > > }
> > > ?>
> > >
> > >
> > >
> > > -------- Original-Nachricht --------
> > >> Datum: Fri, 15 Aug 2008 17:22:52 +0200
> > >> Von: Bruno Friedmann <[EMAIL PROTECTED]>
> > >> An: Matthias Coy <[EMAIL PROTECTED]>
> > >> CC: fw-general <[email protected]>
> > >> Betreff: Re: [fw-general] Zend_Validate regex way to soluce ?
> > >
> > >> Matthias Coy wrote:
> > >>> Hi there,
> > >>>
> > >>> I don't know about Zend_Validate, but preg_match works with
> > >> unicode-characters. So please read
> > http://www.regular-expressions.info/unicode.html for
> > >> more info, especially the part "Unicode Character Properties".
> > >>> S.th. like
> > >>>
> > >>> [\p{L}\.\-_ ]+
> > >>>
> > >>> could work (untested).
> > >> Thanks for the link.
> > >> I've read it before.
> > >>
> > >> My trouble is the following
> > >> a
> > >> 1 <?php
> > >> 2 echo ( (@preg_match('/\pL/u', 'a')) ? "Supported" : "Non
> > supported");
> > >> 3 die(PHP_EOL);
> > >> return "Supported" on my computers
> > >>
> > >> So something like "Clément" is working well ( with filter->Alnum )
> > >>
> > >> But with the regexp everything is accepted ... and that's not what I
> > want.
> > >>
> > >> Did I really need to extend Alnum to add myself the 3-4 extended
> > >> characters allowed ?
> > >>
> > >>
> > >>> Regards
> > >>> Matthias Coy
> > >>>
> > >>> -------- Original-Nachricht --------
> > >>>> Datum: Fri, 15 Aug 2008 16:42:35 +0200
> > >>>> Von: Bruno Friedmann <[EMAIL PROTECTED]>
> > >>>> An: fw-general <[email protected]>
> > >>>> Betreff: [fw-general] Zend_Validate regex way to soluce ?
> > >>>> Hi All,
> > >>>> I need to allow many special thing to be allowed in a username
> login
> > >>>> field.
> > >>>> (Historical database, so it would nearly impossible to change all
> > this
> > >>>> username)
> > >>>>
> > >>>> I need all Alpha numeric word present in french,english,german
> > language
> > >> so
> > >>>> there a lot's of à é ö ü etc ...
> > >>>> Plus username could contain _ - . and space
> > >>>>
> > >>>> isAlnum doesn't work ( I'm not surprise about that )
> > >>>> so I think I need to work with the regex filter
> > >>>>
> > >>>> Is there some expert around with regex which can give me the
> working
> > >> regex
> > >>>>
> > >>>> [tests-case-good]
> > >>>> Clément
> > >>>> Hans Höln
> > >>>> Ioda-Net
> > >>>> Marius_Glad
> > >>>> Micky.128
> > >>>>
> > >>>> [test-case-bad]
> > >>>> Some!thing
> > >>>> Real[Name]
> > >>>> Zut^Truc
> > >>>>
> > >>>> I will really thank peoples who can help me on this case.
> > >>>>
> > >>>>
> >
> > --
> >
> > Bruno Friedmann
> >