1. REGISTRATION REQUIREMENTS:

    Register with your xenforo.com Username then start a conversation at xenforo.com w/Bob and provide the following:
    1. Your XenForo License Validation Token
    2. The Domain Name associated with the License
    NOTE: Your account will be validated once ALL requirements are verified/met. Thank you for your patience.

RegEx Examples for Custom Fields

Discussion in 'Showcase Support' started by MattW, Mar 20, 2013.

  1. MattW

    MattW Server Admin Article Mgmt System EA User Blogs System EA Showcase EA

    For 2 of my custom fields, I'm using Regular Expression to make sure they are formatted correctly, and that members can't take the piss with them (BHP and Torque)

    For this, I'm limiting them to < 999.99 bhp and lb/ft and they can enter upto 2 decimal places, or whole number

    This is the regex I'm using:

    Code:
    ^\d{2,3}\.?\d{0,2}?$
    ^ - start of anchor
    \d - Numbers
    {2,3} - between 2 and 3 numbers in length
    \.? - escaped the decimal place, and set it as optional with ?
    \d{0,2}? - 2 numbers after decimal place and also set optional with ?
    $ - end of string anchor
     
    alfa1, Ludachris, 0xy and 1 other person like this.
  2. Bob

    Bob Developer Staff Member

    Pretty sweet huh? :D
     
    MattW likes this.
  3. MattW

    MattW Server Admin Article Mgmt System EA User Blogs System EA Showcase EA

    Oh it most certainly is! :D
     
    Bob likes this.
  4. MattW

    MattW Server Admin Article Mgmt System EA User Blogs System EA Showcase EA

    and another one to correctly format the year (YYYY)
    Code:
    [1-2][0-9][0-9][0-9]
    I only want them to be able to enter 1 or 2 for the first character. I could build it out and make it more specific, but hopefully my members aren't going to be that retarted ;)
     
    Bob likes this.
  5. MattW

    MattW Server Admin Article Mgmt System EA User Blogs System EA Showcase EA

    Bit more customisation

    additional_information.PNG

    This is using the Value Display HTML to apply the extra formatting on the end of the value the member enters.

    Nice and easy:
    Code:
    {$value} bhp
     
    BT012SS and Bob like this.
  6. woei

    woei Member Showcase

    Thanks, also using the regex for my custom fields now :)
     
  7. Ludachris

    Ludachris Active Member Showcase EA

    Question on this regex - is it set to allow 0 or 2 numbers after the decimal point?
     
  8. Creaky

    Creaky New Member Article Mgmt System EA Showcase EA

    Is there a way of converting 60362 to 60,362, adding the comma, using regex. This isn't something I'm very good with.