Log in

View Full Version : Regex for an empty field


sarahk
09-07-2008, 10:11 PM
I've created a custom field for registration only and it is supposed to be left blank.

I'd like to use the regex field to test that the field is still blank and use the internal vB checking and error reporting system to reject the registration if the user has entered anything at all in the field.

Regex seems to be great for testing patterns, and the inclusion of characters. How do I get it to test for the emptiness?

Eikinskjaldi
09-07-2008, 10:57 PM
Don't bother with regex, just trim the field and see if the result is an empty string

$field = trim($field)
if ($field != '') ...

sarahk
09-08-2008, 06:04 AM
thanks, but I got it going.

I'm trying to keep it simple and not use plugins or hacks - just stick to the core of vB.

vB allows us to check the value of the field using regex, so it makes sense to utilise that functionality.

I have no problem with using plugins where that's the only way but when there is a built in alternative ...

Dismounted
09-08-2008, 06:30 AM
.+
Simple :p

sarahk
09-08-2008, 08:33 AM
actually, it turned out to be

^$

Yours, I think, would allow any amount of text, when I want none.

Dismounted
09-08-2008, 09:15 AM
Whoops, you are correct. I thought you meant you wanted not to allow a blank field. Sorry. :o