MyBB Community Forums

Full Version: Custom Profile Field Regular Expression Error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Right so - I've recently added two new custom profile fields. One checks that the input is a valid image URL using https:// and the other input is a #000000 hex colour code.

The more complex image regular expression works perfectly as expected, the hex colour validation does not, it even throws PHP warnings...

Quote:^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$

I even colour coded it. Toungue

Is there any reason this doesn't work for PHP/PCRE?
Are there no regular expression wizards here? Sleepy
I may be mistaken, but I seem to recall that PHP requires open and close tags for the REGEX.

/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/

Also, depending if you used single or double quotes, you may need to escape the dollar sign (indicates start of a variable's name in double quotes).
# is used as an opening and closing tag (https://github.com/mybb/mybb/blob/mybb_1...r.php#L588), and thus needs to be escaped.
Additionally, there's no need to account for uppercase letters as profile field expressions are always case insensitive:
^\#([a-f0-9]{6}|[a-f0-9]{3})$

And if you'd like to allow empty values:
^(|\#([a-f0-9]{6}|[a-f0-9]{3}))$
Thanks Devil, I figured it had something to do with MyBB specific parsing. Smile