ghostwalkz Posted June 24, 2008 Share Posted June 24, 2008 Hi All, Got a bit of a problem, heres the code: -----snip if (ereg('^[A-Za-z0-9!#$%&()+/£-.:;@\^_{}~]*$', $this->username) || strlen(utf8_decode($this->username )) < 2) { $this->setError( JText::sprintf( 'VALID_AZ09', JText::_( 'Username' ), 2 ) ); return false; } -----unsnip How can I get symbols like () or <> or | (pipe) inside that ereg, they are special characters how do I escape them so that I can use them in a username? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/111711-ereg-and-brackets-or-or-pipe/ Share on other sites More sharing options...
discomatt Posted June 24, 2008 Share Posted June 24, 2008 Backslash will escape special regex characters... but inside a character class ( [ ] ), there is a different set of special characters. Pipes, brackets and less/greater thans aren't in there. Quote Link to comment https://forums.phpfreaks.com/topic/111711-ereg-and-brackets-or-or-pipe/#findComment-573423 Share on other sites More sharing options...
ghostwalkz Posted June 24, 2008 Author Share Posted June 24, 2008 The above code basically is supposed to allow those characters in a username. BUT... things like & (even tho it seems to be present in the above ereg, and pipe, along with curly brackets () and others still fail, how can I modify that ereg to allow all characters as a username. ;-) Quote Link to comment https://forums.phpfreaks.com/topic/111711-ereg-and-brackets-or-or-pipe/#findComment-573433 Share on other sites More sharing options...
effigy Posted June 24, 2008 Share Posted June 24, 2008 Your pattern gave me a ranging error because £-. is not a valid range. If you want to match a literal hyphen within a character class it is best to place it first. Quote Link to comment https://forums.phpfreaks.com/topic/111711-ereg-and-brackets-or-or-pipe/#findComment-573514 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.