Muffin Posted February 8, 2007 Share Posted February 8, 2007 I'm trying to set up a registration page that, before creating the account, queries a table to find if the username the person selected contains a word in said table. I tried using a SELECT LIKE until I realized (about 3 hours later) that it won't work unless the username is exactly one of the restricted words, or shorter. If that's not too clear, here's an example; User selects the name "{DvT}Muffin" If the word {DvT} exists in the restricted names list, then stop the registration and return an error. I'm pretty new to php, but even if a solution is rather complex, throw it at me anyway. Link to comment https://forums.phpfreaks.com/topic/37618-solved-trying-to-set-up-a-restricted-word-list/ Share on other sites More sharing options...
obsidian Posted February 8, 2007 Share Posted February 8, 2007 Basically, rather than using your username to query against the table, I would select your list of restricted words and match your username to them instead. For instance: <?php $username = "DvTMuffin"; $valid = TRUE; // default to true unless you find a match $sql = mysql_query("SELECT word FROM restricted_table"); while ($x = mysql_fetch_array($sql)) { if (preg_match("|" . $x['word'] . "|i", $username)) { $valid = FALSE; } } if ($valid) { // Process username } ?> Link to comment https://forums.phpfreaks.com/topic/37618-solved-trying-to-set-up-a-restricted-word-list/#findComment-179914 Share on other sites More sharing options...
Muffin Posted February 8, 2007 Author Share Posted February 8, 2007 I'll give that a try in a sec, but a question. Wouldn't that only check if the restricted word was at the start of the name. I would like it to check for the restricted word wherever it may be in the name. Link to comment https://forums.phpfreaks.com/topic/37618-solved-trying-to-set-up-a-restricted-word-list/#findComment-179926 Share on other sites More sharing options...
obsidian Posted February 8, 2007 Share Posted February 8, 2007 I'll give that a try in a sec, but a question. Wouldn't that only check if the restricted word was at the start of the name. I would like it to check for the restricted word wherever it may be in the name. No, as it is, it will simply check to see if the word appears anywhere in the name. If you want to check that it starts with the word, you'd need to modify your regexp to something like this: <?php $regexp = "|^$x[word]|i"; if (preg_match($regexp, $username)) { $valid = FALSE; } ?> Link to comment https://forums.phpfreaks.com/topic/37618-solved-trying-to-set-up-a-restricted-word-list/#findComment-179930 Share on other sites More sharing options...
Muffin Posted February 8, 2007 Author Share Posted February 8, 2007 Thankyou heaps for that, it was a big help. It was starting to drive me nuts. Link to comment https://forums.phpfreaks.com/topic/37618-solved-trying-to-set-up-a-restricted-word-list/#findComment-179934 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.