takn25 Posted February 17, 2011 Share Posted February 17, 2011 Hi, I am getting slightly better with REGEX. Searched everywhere for a good tutorial on repetitive characters but no luck. Could some one guide me how can i achieve the desired result. The thing I am after is to check a string, for repetitive characters for instance a name I don't want a user to input as "WWWWWWWWilliam" what I want to create is to check that any alphabet is not used repetitively more than 3 times e.g WWW or AAA and not AAAA. Any help would be greatly appreciated thanks. Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted February 17, 2011 Share Posted February 17, 2011 Are you just wanting to list all matches that do? Or are you wanting to replace them with just one of that character, something like this $result = preg_replace('/([a-z])\1{2,}/i', '$1', $subject); Note that this is case insensitive Quote Link to comment Share on other sites More sharing options...
takn25 Posted February 18, 2011 Author Share Posted February 18, 2011 I just want to display an error to the user saying you can not use so many repetitive characters for your name. Quote Link to comment Share on other sites More sharing options...
.josh Posted February 18, 2011 Share Posted February 18, 2011 $subject = "WWWWWWWWilliam"; // example if (preg_match('~[a-z]{4,}~i',$subject)) { // has more than 3 letters in a row } Though I can't help but question why you feel the need to police something like this... you should only be enforcing stuff from a security or practical PoV, not a "this is my personal opinion" point of view. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 18, 2011 Share Posted February 18, 2011 Though I can't help but question why you feel the need to police something like this... you should only be enforcing stuff from a security or practical PoV, not a "this is my personal opinion" point of view. Agreed 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.