Forum Moderators: coopster
Maybe someone here can help me out. I have been using a standard Wiki REGEX to validate WikiNames:
preg_match("/^[A-Z,ƒ÷‹][a-z,fl‰ˆ¸]+[A-Z,ƒ÷‹][A-Z,a-z,0-9,ƒ÷‹,fl‰ˆ¸]*$/", $text)
(That fl is a special character that doesn't translate well to browser display).
I had issues with adding numbers to the name, such as "P123projectPage4", so I changed the REGEX like so:
preg_match("/^[A-Z,ƒ÷‹][a-z,0-9,fl‰ˆ¸]+[A-Z,ƒ÷‹][A-Z,a-z,0-9,ƒ÷‹,fl‰ˆ¸]*$/", $text)
I guess I could also make the numbers part of the capital requirements, like so:
preg_match("/^[A-Z,0-9,ƒ÷‹][a-z,fl‰ˆ¸]+[A-Z,ƒ÷‹][A-Z,a-z,0-9,ƒ÷‹,fl‰ˆ¸]*$/", $text)
Any feedback?
Can you post some examples of the [Wiki]Names you are referring to?
Sure. Here's what I have posted as the current allowables in our wiki:
* Is Not a WikiName: notawikiname (All lowercase)
* Is Not a WikiName: NOTAWIKINAME (All uppercase)
* Is Not a WikiName: NOTAWikiname (Does not have lowercase letters between capital letters)
* Is Not a WikiName: NotAWiki_Name (Contains non-alphanumeric character)
* Is Not a WikiName: 4AnExample (Starts with a number)* Is a WikiName: IsAWikiName
* Is a WikiName: IsawikinamE
* Is a WikiName: Isawikiname2
* Is a WikiName: Is2AWikiName
Here [en.wikipedia.org] is the official Wikipedia description of CamelCase.
Here [c2.com] is an even older definition.
As you can see, there are no hard and fast rules.
Our wiki insists that the first letter always be capital, and that it be alphabetic (A-Z). It can then be followed by lowercase alphabetic characters, then by a mix of numbers and alphanumerics, with subsequent capitalized letters.
What I did was add the ability to create the following type of name:
* N123umbersRightAfterACapital
Before, you had to have a lowercase letter right after the first letter:
* Nu123mbersRightAfterACapital
If you wanted to hold true to the Wiki format you could always pull their source code down and locate the regular expression they are using to build names. As a matter of fact, you could start with what they have and modify yours from there if you so desire. I believe the function might be found in their
importUseModWiki.phpfile.
BTW, you don't need to separate ranges in a character class with commas. As a matter of fact, having the comma there means you are allowing the comma character to be part of the expression. Are you certain that is what you want?
In the meantime, I have a Regex homework assignment. I suspect that it will be easy.Here is the current WikiName regex in the Wiki:
function IsWikiName($text) { return preg_match("/^[A-Z,ƒ÷‹][a-z,0-9,fl‰ˆ¸]+[A-Z,ƒ÷‹][A-Z,a-z,0-9,ƒ÷‹,fl‰ˆ¸]*$/", $text); }
I actually added the ,0-9 in the second set of brackets, but I'm not so sure I like the results. I think the whacky characters may be because of
Cyrillic character sets (the authors are Russian).In any case, I want to get rid of the Cyrillic characters, and I'm pretty sure the commas are not supposed to be there.
Here are the rules:
The first letter of a WikiName must be an uppercase English/Roman character (A-Z). It cannot be numeric or punctuation.
No non-alphanumeric characters anywhere ([A-Za-z0-9]).
Numbers 0-9 should be classified as capital letters.
There must be a switch between capital letters and lowercase letters, followed by at least one capital letter.
Examples:
ThisIsAWikiName
thisIsNotAWikiName
THISISNOTAWIKINAME
thisisnotawikiname
Thisisnotawikiname
ThisisawikinamE
Thisisawikiname2
1ThisIsNotAWikiName
ThisIs_Not_AWikiName
ThisIs.Not.AWikiName
THISisnotawikiname
THISis2awikiname
T123HISisAwikiname
T123HISisnotawikiname
T123HISisa4wikiname
T123HISISNOTAWIKINAME
YeS
NoThink you can give me a regex that will do this?