Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. Well the lookahead bit looks ahead and verifies the format (without actually consuming anything) and then that .* afterwards is what actually matches (and consumes) the string. So I guess *technically* you can swap the 2nd dot instead of the first, it effectively does the same thing. TBH I'm not 100% sure which way is technically more efficient (would have to do some benchmarking) but my thought was this: You are effectively matching for stuff twice (sort of) so IMO the more validation put in the first match (the lookahead) would theoretically mean less double matching. IOW, if the string is destined to match, it's going to have to go through two sets of matches (sort of), but if it fails, it will only go through one. But lookaheads in general have a bit of overhead so it might turn out that it would be slower overall...again, only way to really know is to do some serious benchmarking against a bunch of strings. But regardless, we're talking fractions of microsecond difference, so it doesn't *really* matter... But on the point of it matching twice (sort of) ... yeah so that was my point about the lookahead being superfluous: you're basically performing the same match twice. Sort of. You kind of split it up between the two (the character length range in the lookahead, and the allowed chars in the following consuming match (in your version) .. and then both are looking for end of string with that $). So for sure the MORE efficient thing would be to get rid of one of them. Technically since you aren't actually trying to capture anything, you could move everything to one or the other (only have a lookahead, or else ditch the lookahead). I'm fairly certain lookaheads are less efficient in general so I opted to remove the lookahead and put everything as a normal consuming match. But none of this is a "bad" thing per se...it mostly matters how much you want to nickle and dime efficiency and readability. But since you seem to be a fan of readability (the comment mode), then it might be prudent for you to go ahead and simplify it. On the note of comment mode: you can still leave that in if you want to, of course. IMO it actually makes it less readable, but maybe that's just me...I am pretty used to reading regex. Whatever floats your boat. RE: Unrelated topic: Yes you are correct, having a single regex will prevent you from being able to give more specific form errors. IMO that is okay. I think most of the time people fail to use the proper format is because they fail to read the format instructions in the first place. IMO listing a general error of what all could be wrong with it (that list you have above) is more than acceptable for allowing the visitor to figure out what they did wrong. I rarely see clients or websites in general I've been to, be so granular in their error messages. But at the end of the day, it's up to you. If you really wanted to take the "scientific" approach to finding out which offers better UX, you could do some A/B testing on your forms (Omniture Test and Target, Google Optimize, etc..), see which ones lead to more people filling out forms. But if you do decide to be more granular about it, then yes, you will need to separate the regex out into multiple conditions, addressing each format requirement. .josh
  2. Welp, to immediately answer your question with the path of least resistance, you will need to change: (?=.{8,30}$) to (?=[a-z0-9_.-].{8,30}$) Dollar Sign signifies end of string (or line, if you use the appropriate modifier). But anyways...I'm kind of curious as to why you would use a lookahead for this in the first place (I know you mentioned you got help from someone else, so I'm not "blaming" you)...maybe there is some thing more involved here that you haven't provided in this post, but at face value you don't need a lookahead, can just use: if (preg_match('~^[a-z0-9_.-]{8,30}$~i', $trimmed['username'])){ // Valid Username. }
  3. if it is indeed on the same domain, you can reference it with the parent object: window.parent.someFunction. If the parent window and iframe window do not share the same domain, then it is not possible, as this is cross-site-scripting.
  4. This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=358545.0
  5. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=358535.0
  6. My 61 y/o mom does database entry and data mining, she can make db queries that even fenway would be proud of...but when it comes to absolutely anything else with computers...seriously, I've had the "did you check if it's plugged in? ... yep, that would do it..." moments with her. Older generation people .. they weren't really around computers all their lives, esp as younger kids who could just mash buttons and see what happens. They were put in front of computers and taught to push very specific buttons, do very specific things, and nothing else.
  7. Yeah, I've used the "retard talking to mechanic" analogy a lot of times in tl;dr posts...pretty good go-to analogy.
  8. There is a "workaround" that effectively does the same thing. On the top right or bottom right of a thread is a "Notify" button. You can click on it to set the thread to notify you if people post in it. Now, if you go to Profile > Notifications You will see a listing of all threads you want to be notified on. Also on this screen you can change it to where you do not actually get notifications if you don't want to actually get notified.
  9. Numbers calculated using this benchmarking function. Round 1: times executed (each): 250000 fastest to slowest: Array ( [josh_pure] => 0.00000539963519708157 [ManiacDan] => 0.0000057829462635701 [josh_blended] => 0.0000060079560636085 ) biggest difference time: 0.00000060832086652693 fastest is 11.266% faster than the slowest Round 2: times executed (each): 250000 fastest to slowest: Array ( [josh_pure] => 0.00000552566420531364 [ManiacDan] => 0.00000584143936571746 [josh_blended] => 0.00000610485283878271 ) biggest difference time: 0.00000057918863346907 fastest is 10.4818% faster than the slowest Round 3: times executed (each): 250000 fastest to slowest: Array ( [josh_pure] => 0.00000537841102728821 [ManiacDan] => 0.00000559228 [josh_blended] => 0.00000604077199996 ) biggest difference time: 0.00000066236097267179 fastest is 12.3152% faster than the slowest 18165_.txt
  10. pure regex: if ( preg_match('~^[a-z]*-?[a-z]*$~',$string) ) { // valid } else { // invalid } blended...may possibly be a little faster: if ( (substr_count($string,"-")<=1) && (preg_match('~^[a-z-]$~',$string)) ) { // valid } else { // invalid }
  11. kinda hard to help you without seeing any code... but if I had to guess, your icon swapping function sounds like it is working but your form is submitting anyways. IOW you're forgetting to return false somewhere, to block it from actually submitting. And I can only guess (again, no code posted) that you have a single form script that submits to itself and it's just outputting the original form again because of some server-side logic telling it to do it if form has not been filled out.
  12. need the "s" modifier so that your "." will match newline chars.
  13. This will throw those 3 chars into the mix, to match up to. It says to match one or more of anything that is not a space, comma, pound or colon: $description = preg_replace("/#([^ ,#:]+)/", "<a href=\"https://twitter.com/#!/search/%23$1\">#$1</a>", $description); or alternatively, this will just match one or more word char (letter, number or underscore) $description = preg_replace("/#(\w+)/", "<a href=\"https://twitter.com/#!/search/%23$1\">#$1</a>", $description);
  14. create a duplicate profile with same filters and wait a week or two for some traffic to flow in. Remove the filter on the dupe and wait another week or sooner to compare numbers with main profile.
  15. We also have in red letters above the post buttons a warning....
  16. Okay so the way your pattern works... 1) You are using ^ as the pattern delimiter. While it is technically okay to use (most) non-alphanumeric characters as the pattern delimiter, you should avoid using characters that have special meaning to the regex engine. ^ is a marker to signify start of string or line (depending on modifiers used), and also used for negative character classes, so you want to avoid that. I use ~ in as my delimiter because it has no special meaning to regex engine and it also rarely comes up in the subject I need to regex. But on the note of specifying start (and end) of string... 2) Your pattern does not specify start or end of string. What this means is that your pattern will not just match for example "D34V78", it will also match "anythinghereD34V78orhere". So in order to tell the engine to evaluate the string as a whole, IOW "the entire value of this string must be this format, not just some substring within it", you have to specify beginning and end of string, with ^ and $, respectively. 3) Wrapping your (sub)patterns in parens (...) (capture groups) is what makes the captured bits of your pattern show up as individual array elements. So your pattern does not wrap that first D in parens, so it will not show up as a captured element. I did mention in my post how I thought this was indeed not necessary, since you said that the string will always start with D, but technically you did specify that it be listed within the matched array, which is why I edited my pattern to capture it. 4) This bit of your pattern: ([A|E|V]) This *works* but it will also match a pipe, for example "D123|456" will match. Why? Okay square brackets [..] is a character class. It will match for one character listed inside the brackets (or match for a character NOT listed in it if ^ is the first character listed within the brackets). So basically that pattern is saying "match for an 'A' or a '|' or an 'E' or a '|' or a 'V'" so basically you just list a pipe 3 times. I can see why you thought to separate the characters with a pipe though, since that is the alternation character. You would normally use the pipe if you want to match for "abc" or "xyz" where the match is more than a single static character (or character range), since a character class will only match for ONE character in the list. IOW, abc|def will match "abc" or "def" but [abcdef] will match "a" or "b" or "c" or "d" or "e" or "f". And [abc|def] just matches the same thing or a pipe. Sidenote: even though character classes can only match for any ONE character in the list, and they must be literal characters (with the exception of escaped characters to signify certain other characters), you CAN specify ranges, such as 0-9 will match for a 0 or 1 or 2 or ... 9 (you get the picture). Which you will see demonstrated in the pattern. So, having said all that, here is the breakdown of my pattern: ~^(D)([0-9]+)([VAE])([0-9]+)$~ ~ pattern delimiter ^ start of string assertion (cannot have anything before what follows) (D) match for and capture a literal "D". As mentioned, IMO capturing it is not necessary since you say it will always be "D". ([0-9]+) match for and capture 1 or more of any single digit number ([VAE]) matched for and capture a "V" or "A" or "E" ([0-9]+) match for and capture 1 or more of any single digit number $ end of string assertion (cannot have anything after the pattern) ~ pattern delimiter So it basically reads as "start at the beginning of the string and match and capture a 'D', followed by 1 or more numbers, followed by one of these 3 characters, and ending with 1 or more numbers"
  17. $string = "D34V78"; preg_match('~^(D)([0-9]+)([VAE])([0-9]+)$~',$string,$parts); print_r($parts); Array ( [0] => D34V78 [1] => D [2] => 34 [3] => V [4] => 78 ) edit: I added a capture group around the first "D" because I noticed you said you wanted the array to include it...but if you say it will ALWAYS Start with D, then I'm not sure why you really *need* it to be captured, but there you have it.
  18. ouch...that's a real eye-opening experience, about the dependency we have on sight! I bet it was very enl-eye-ghtening! aHAHAHAhaHAHAHa! No but seriously, that must have sucked
  19. To directly answer your question, yes, it is possible to "get by" using Linux w/out a command prompt. There are a lot of distros out there that focus on providing an alternative to Windows but with all the "GUI" benefits that make Windows so popular.
  20. you should..probably ask on a more appropriate site, or better yet, ask an optometrist. This is a web development site...this question is so off-the-wall, frankly I'm inclined to suspect spam...
  21. I probably don't really need to state the obvious, but considering this is a php site and we are named phpfreaks, I suspect opinions about php will be biased towards php...
  22. The patent process, and really any U.S. legal process/system/etc.. is actually pretty simple: whoever has the most money to throw at it wins. You can even get away with murder (literally!) if you have enough money to throw at it. Someone takes your code? Take them to court. Because it will cost him money to defend himself. If he wins, sure, you'll have to pay. But...you can appeal, in which case he has to pay to defend himself all over again and get it back from you if he wins all over again. If you lose, appeal. If you lose again, appeal again. Wash, rinse and repeat until whoever has the most money wins. The only reason you see people "losing" or "settling" is because a) they ran out of funds to keep it going, or b) they decide they will lose too much money in the long run (eg: Big Chemical Co. may be blatantly torturing and killing animals while "testing" Brand X but they will certainly get away with it legally if they throw enough money at it...but if enough people decide they won't buy their products, then they are fistcally fucked, so they back down or compromise - which is not really the same thing). Yes it really is that simple, sad and true. In a capitalist system, money is god.
  23. // strip everything but the numbers $number = preg_replace("~[^0-9]~","",$number); This already strips whitespaces and will effectively trim() it; it strips anything that is not a number. And then this: // number is bad if not 10 digits if ( strlen($number)!=10 ) return false; checks to see if what is left over is 10 chars. So basically, the visitor can enter in a phone number in any format they wish, (even " [123]....(456)~7890~ " if they really really wanted to - I hear that's the unofficial format of some smaller towns in Nebraska backwoods areas).
  24. This is what I got from the test. Faster than 91% of all tested websites! Anyways...near as I can tell, most of the load/wait time comes from the 3rd party ads (something you don't get if you become a supporter or named membergroup).
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.