Log in

View Full Version : regex advise plz


Koidl
06-03-2010, 12:50 PM
i am not sure if i use the preg right can someone give me advise i cant use it like that in the profile fields

enteredText = value entered by the user in the field

IF regexCheck("^\d{8,10}$", enteredText) THEN
finalURL = "http:/domain.com/" + enteredText + "/"
ELSE
send error message to user that the value must be between 8 and 10 digits only
END IF


thanks

Speysider
06-03-2010, 01:22 PM
You shouldn't use capital PHP code like IF, ELSE, END IF etc
You'd use something like:
if (whatever condition you want here)
{
result if condition is true
}
else
{
result if the condition is not true
}
Replacing the part between brackets with whatever you want to happen.

Koidl
06-03-2010, 02:02 PM
You shouldn't use capital PHP code like IF, ELSE, END IF etc
You'd use something like:
if (whatever condition you want here)
{
result if condition is true
}
else
{
result if the condition is not true
}
Replacing the part between brackets with whatever you want to happen.

i tryed it like that now but still not working :(

if ("^\d{8,10}$", enteredText)
{
finalURL = "http:/domain.com/" + enteredText + "/"
}
else
{
value must be between 8 and 10 digits only
}

Speysider
06-03-2010, 02:15 PM
Is your regex correct??

Koidl
06-03-2010, 02:39 PM
Is your regex correct??

yes the regex alone works :)

Marco van Herwaarden
06-04-2010, 11:47 AM
You can use:

if (preg_match("REGEX", $string))
{
}
....

See the php manual: http://th2.php.net/manual/en/function.preg-match.php

Koidl
06-04-2010, 12:16 PM
You can use:

if (preg_match("REGEX", $string))
{
}
....

See the php manual: http://th2.php.net/manual/en/function.preg-match.php

i tryed already alot after reading all this examples
but i cant get it working :(

if (preg_match("^d{8,10}$", $string))
{
echo "http:/domain.com/" + $string + "/";
}
else
{
echo "value must be between 8 and 10 digits only";
}

if (preg_match("^d{8,10}$", $string))
{
print_r("http:/domain.com/" + $string + "/");
}
else
{
echo "value must be between 8 and 10 digits only";
}

Marco van Herwaarden
06-04-2010, 12:32 PM
And what is not working and where do you place this?

Koidl
06-04-2010, 12:41 PM
i placed it in a costumer profile field under "Regular Expression"
the regex is working but it dont transforms it in a link also the error message for wrong valve is not working

Marco van Herwaarden
06-04-2010, 01:02 PM
In a custom profile field you can only place an expression that results in true (1) or false (0). You can not perform actions like showing a text.

See the admin help for this field by clicking on the question mark at the right of the field.

Koidl
06-04-2010, 01:08 PM
In a custom profile field you can only place an expression that results in true (1) or false (0). You can not perform actions like showing a text.

See the admin help for this field by clicking on the question mark at the right of the field.

too bad suppose i missunderstood than something
thanks anyway

Marco van Herwaarden
06-04-2010, 01:20 PM
Maybe try to explain what you want with this.

You could use the Custom Profile Field with a RegEx to make sure only a certain format is entered. Then where you want to display it you can use a small template edit to create a link of website URL + the number entered as i think this is what you want to do.

Koidl
06-04-2010, 04:03 PM
Maybe try to explain what you want with this.

You could use the Custom Profile Field with a RegEx to make sure only a certain format is entered. Then where you want to display it you can use a small template edit to create a link of website URL + the number entered as i think this is what you want to do.

the input is a playernumber for a game and this site where i wanna make a link out of it is a stats site both together should be there personal statslink

well example
my player number = 2345678
and after i past it in my profile (the number) it makes a link out of it (result)
http://domain.de/2345678/ this link should be stand there than instead of the number or just the number but be clickable but link to this link

about the template edit would i edit all profile fields than? because we have more different

the final link is there personal stats site than
sorry for my english :D

btw the regex only stuff works pretty fine alone ..