1. REGISTRATION REQUIREMENTS:

    Your username here MUST MATCH your XenForo username (connected to your XF license).

    Once you have registered here, then you need to 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 AMS Premium CAS Premium RMS Premium SC Premium UBS Premium

    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
     
    wjosh45, alfa1, Ludachris and 2 others like this.
  2. Bob

    Bob Developer Staff Member

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

    MattW Server Admin AMS Premium CAS Premium RMS Premium SC Premium UBS Premium

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

    MattW Server Admin AMS Premium CAS Premium RMS Premium SC Premium UBS Premium

    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 AMS Premium CAS Premium RMS Premium SC Premium UBS Premium

    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 AMS Premium CAS Premium RMS Premium SC Premium UBS Premium

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

    Creaky New Member AMS Premium SC Premium UBS Premium

    Is there a way of converting 60362 to 60,362, adding the comma, using regex. This isn't something I'm very good with.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.