Hello, Im trying to use coldfusion cfif to check if a user is registering with an email address which must be thename@leeds.ac.uk Any ideas how to achieve this? Thanks
Hello bruhol, Assuming the user is coming from a sign-in form you can use the following snippet. <cfif FORM.EmailAddress EQ "thename@leeds.ac.uk"> TRUE <cfelse> FALSE </cfif> Hope this helps.
Hi Jason, Thanks for your reply. Having thought more about my problem, the real answer is to validate email addresses supplied by users wanting to register, against active directory using cf and ldap but thats way above my knowledge. What I have done though is to treat the email input as a text input field and ask for their name only. Then I take that value and concatenate the @leeds.ac.uk part to that before submitting it to the database. I also use cffindnocase to check that they have not accidentally input the @ symbol. Bit long winded but it does go some way to restricting who is allowed in. I decided that there should be no gatekeeper preventing immediate use of the application hence the need to focus on the email address. If anyone knows how to use ldap with cf I'd appreciate some help here. Example below. form action >> <cfset form.email = part_1> <cfset '@leeds.ac.uk ' = part_2> <cfset part_1 & part_2 = email> database action >>
Hello again bruhol, I haven't had a chance to play with LDAP, but I think you can determine whether or not the email address is valid a bit easier with the user defined function here on CFLib.org http://www.cflib.org/udf.cfm?ID=216
bruhol, For now there's nothing wrong with using a string functions. I often use a test like this. It trims leading/trailing spaces then uses list functions to extract the "name" portion. So it works for form.name = "theName" form.name = "theName@" ... and even for a full email form.name = "theName@leeds.ac.uk" <cfset form.name = trim(form.name)> <cfset form.name = listFirst(form.name, "@")> <cfset variables.email = form.name &"@leeds.ac.uk"> Code (markup): I haven't used CFLDAP in a while but from what I remember it was easy. Just like doing a query. There are tutorials on it, both CFLDAP and using LDAP in general. http://tutorial336.easycfm.com/ http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-p69.htm
Though if you just wanted to validate the email string the function JasonBartholme suggested is good. You can also use the IsValid() function if you're using MX7+
This works too: <CFSET Valid = true> <CFSET Error = ""> <CFIF IsDefined("Form.email")> <CFSET email = "#Form.email#"> <CFELSE> <CFSET email = ""> </CFIF> <cfif len(#form.email#) LTE 0> <CFSET Error = Error & "Email Address is empty.<BR>"> <CFSET Valid = False> <cfelse> <cfif REFindNocase("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name))$", email)> <cfelse> <CFSET Error = Error & " You entered an invalid email address.<BR>"> <CFSET Valid = False> </cfif> </cfif> <CFIF not Valid> <STRONG>Sorry, An error occurred</STRONG> <HR> <CFOUTPUT><font size="+1" color="660000">#Error#</font></CFOUTPUT> <EM>Please correct the error/errors</EM><br> <A HREF="javascript:history.go(-1)"><br>Click Here To Return</A> </cfif> Code (markup):