Nhoj Posted September 6, 2006 Share Posted September 6, 2006 I just recently developed a user registration system, not a hard thing at all to make, and i use the code:[code]preg_match_all('/(?:([a-z]+)|.)/i', $_POST['username'], $matches);$_POST['username'] = implode('', $matches[1]);[/code]To strip EVERYTHING that is not alpha numeric from all of the registration inputs and it works exactly how I want it to, however, this also strips the @ sign and periods, which is bad for e-mails.Is there any way to have it do what it does now except add '@' and '.' to the safe list? This way only alphanumeric characters and those two symbols will remain.Thanks,John Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 6, 2006 Share Posted September 6, 2006 i would just use preg_replace() instead like this:[code]<?php$String = preg_replace('|[^a-z0-9.@]|', '', $String);?>[/code]make sense? Quote Link to comment Share on other sites More sharing options...
Nhoj Posted September 6, 2006 Author Share Posted September 6, 2006 Not sure why I didn't even consider preg_replace, anyway, thanks. I'm using what you suggested with the exception that I added an extra A-Z to allow capital letters. Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 6, 2006 Share Posted September 6, 2006 [quote author=Nhoj link=topic=107154.msg429503#msg429503 date=1157574158]Not sure why I didn't even consider preg_replace, anyway, thanks. I'm using what you suggested with the exception that I added an extra A-Z to allow capital letters.[/quote]you could just add the "i" for case insensitivity:[code]<?php$String = preg_replace('|[^a-z0-9.@]|i', '', $String);?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.