Skip to main content
September 1, 2010
Question

Problem with a structure, how to set a conditional variable inside

  • September 1, 2010
  • 2 replies
  • 547 views

Not sure if I titled it correctly, but I have created a structre:

<cfset email.fields[1] = StructNew()>

<cfset email.fields[1].required = true>

<cfset email.fields[1].label = 'County Email Address'>

<cfset email.fields[1].displayIcon = false>

<cfset email.fields[1].regEx = "^.+@jason.com$">

<cfset email.fields[1].externalSource = newExternalSource()>

The line taht is bolded and underlined is the line I am having issues with. Basically I have set the variable to a particular email address, and the way the struct is set up, the users are only allowed to enter that email address. My issue is, that this particular client has 2 email address that their users can enter. I am not sure how to accomplish this within the structure, if it is possible at all. For example, here is what I would like to do, although the syntax is incorrect:

<cfset email.fields[1].regEx = "^.+@jason.com$" OR "^.+@tommy.com$">

    This topic has been closed for replies.

    2 replies

    Inspiring
    September 1, 2010

    Regarding:

    and the way the struct is set up, the users are only allowed to enter that email address.

    Why not just present the allowable entries in a drop down?

    September 1, 2010

    well its a situation where I have a new job, and I am parsing through the old developers code. Just try

    ing to make a quick fix without reinventing the wheel sort a say. The drop down would be the easier solution, but that would require much more investigation at this point, and I have a pretty full plate as it is. Some of this code is a mess.

    Inspiring
    September 1, 2010

    I don't think you're approaching it from the right direction.  You're not wanting to set the value conditionally on something, you just want a regex that will match both email addresses.

    For your example, it'd be:

    ^.+@(jason|tommy)\.com$

    (note that the existing regex is slightly wrong, in that you should be escaping the "." in ".com". I have reflected the correct approach in my example.

    --

    Adam

    September 1, 2010

    how do I hadle it if they are not both a .com?  For example 1 email is a .com, and the other is a .us