custom Profile Field, Validation of Input Mask, Regex Problem

Started by petb, May 23, 2012, 03:55:29 AM

Previous topic - Next topic

petb

Hi,

i use a custom Profile Field.
i use a validation Input Mask.
i place the following in the "Vaildation Input Mask" Field
[ [ :alnum: ] ] { 3 , }
but without any spaces !

But this produces the Error:
http://www.forumname.com/index.php?action=profile;area=account;u=XXX;save
2: preg_match() [<a href='function.preg-match'>function.preg-match</a>]: Unknown modifier '{'
File: /var/www/forumname/Sources/Profile-Modify.php
Row: 1307


Could someone please tell me whats wrong wit that Expression ?
If i use it in a Regex-Vailidater, it was working fine.
Allows alnum and has to be at least 3 Chars long.
But placing this in the Field gives the Error.

Also some examples with  Brackets from the Help Section under the ? produces the same Error.

MrPhil

Try (without spaces)
/[a-z0-9]{3,}/i
The / are the delimiters needed for preg_* calls.

It sounds like there's some documentation that needs updating (written for old "ereg" calls).

Arantor

Or not, as it happens.

The documentation is absolutely correct, only no-one ever reads it properly. The examples given have " delimiters provided and will work exactly as intended if copy/pasted.

(You can use any character you like as a regex delimiter provided that it is the first character of the string, / is the default, but internally SMF uses ~ in most places because of the various URLs it validates, wherein using ~ means you don't have to escape /)

MrPhil

The documentation may be technically correct, but it's wrong if it misleads users. Using " for a delimiter is poor practice (even if allowed for preg_*) because it will be read (by people) as enclosing a string, and thus can be discarded.

I have seen this complaint before, and my understanding is that the documentation dates back to the days of using ereg() calls, where there is no delimiter and indeed, the quotes can be discarded.

Arantor

I dunno, I never read it that way and it worked first time when I copy/pasted it, as the original developers intended it to be - since they figure that most people didn't really want to be bothered with 'the complexities' of normal regular expressions.

(Hey, I have as much reason to be biased about the frailties of SMF's code in places but I will defend them if it is actually right!)

petb

 O:)
I have allready used the Examples, copy & paste exactly, but:
Using " as Delimiter produce an empty Field, after store the Mask in the DB

So now i try the Example from
Quote from: MrPhil on May 23, 2012, 10:32:50 AM
Try (without spaces)
/[a-z0-9]{3,}/i
and also with alnum.

This looks like it was working fine.
In the Registering Process i have to type at least 3 Chars or Nums to prevent from an Hint.

So thanks, ... damned i never tried an other Delimiter than " because i thought if this, from the example wont work, nothing will work.
And also i never thought about mask anything. :-[ :-[ :-[

But, Arantor, i really copy & Paste the Example and after storing, the Field was Empty, the REGEX was lost.

Arantor

*shrug* It worked for me when I first tried it, because at the time I didn't know what it was expecting...

But that was a long time ago now, back when 2.0 was still in early beta (a.k.a. RC1)

Advertisement: