I'm programming a honeypot for vBulletin and I have the opportunity to have the field tested against a regular expression. Does anyone know how I'd do this to check that the field is empty? thanks
I don't see why you'd want to use regex for this. Just check if it evaluates to boolean false ("if (!$field)...")
^ I'm guessing this has something to do with vB's options? Anyway, using regular expression, you could do this: '~^$~' PHP:
Yeah, you can use the above regex, although why you can't just test the length of the field with strlen() I'm not too sure
I've seen you using strlen() a lot in your blog, and I think it's kinda redundant too. You can just do: if (!$field) { // ... } PHP: ... which returns false on empty strings too, and it's a function call less. Or even: if (!$field = trim($field)) { // ... } PHP: ... to make sure the field doesn't contain just empty spaces. EDIT: And least, you could do: if (!empty($field)) { // ... } PHP: ... which does the same as isset() and (bool)$field at the same time. It's faster too, since it's a language construct.
Testing the field contents is an option but requires writing a plugin which is one more thing to migrate, test etc. If I can use the existing architecture to test the field (which is why the regex test is there in the first place) I am reducing the risk of problems in the future. I'll give that a go, thanks