PDA

View Full Version : Regular Epression for Profile Fields Discussion


gamerfu
04-03-2009, 11:58 PM
I am trying to figure out how to code the regular expression as a valid expression for:

0123-4567-8901

I only want to accept '0123456789' and the '-' characters.

Here is the regular expression code vBAdminCP links to:
http://us3.php.net/manual/en/function.preg-match.php

But, I am a bit confused how to control this expression for a mix of numbers and the dash character with the above bolded format.

All ideas welcome. :cool:

Dismounted
04-04-2009, 05:40 AM
^[0-9]{4}-[0-9]{4}-[0-9]{4}$

gamerfu
04-04-2009, 04:21 PM
That helps a lot! :cool:

Thank you! :cool:

Dismounted
04-05-2009, 05:01 AM
There's probably a simplified way of doing it, but I just simply don't know. (I hatedislike regex. :p)

TigerC10
04-06-2009, 07:17 AM
I would use:

^[0-9]{4}-[0-9]{4}-[0-9]{4}$|^$


That way, the profile field doesn't complain when a user enters a blank. Because the regex overrides the "field required" setting.

gamerfu
04-06-2009, 01:35 PM
I added the extra code. :cool:

Thank you for the tip. :cool: