1 2 Previous Next 16 Replies Latest reply on Sep 18, 2015 1:58 PM by sumaschu

    Validating "@" Exists in an Email with Show Custom Dialog

    sumaschu

      Hi all Gurus!

       

      As always, thank so much for this valuable service you all provide.  You all are awesome and very much appreciated!

       

      Have a couple of text "email" fields (PersonalEmail and WorkEmail, so far) on a Layout.  When the data is entered into the field, have it perform a "Calculated Value" within the Auto-Enter tab to check for no more than one "@" symbol and at least one "." (accommodate for a .com, .edu, etc), to change the color of text to red using:

       

      If(

      PatternCount(Self;"@")<>1

      or

      PatternCount(Self;".")=0
      ;

      TextColor(Self;RGB(255;0;0));

      TextColor(Self;RGB(0;0;0)))

       

      It works beautifully in changing the color of the text to red when the data falls outside these parameters (thanks Discussion)!  [And yes, I am aware that if there is a "." between a first name and a last name (ex: john.doe@emailcom), it will errantly not flag the email address as invalid, when it is indeed invalid (missing the "." between "email" and "com").  Some sort of validation is better than no validation in my experience.]

       

      Now, before saving the data within the Layout, want to check with a Script if there are any "red text" fields that haven't been addressed for just the email fields.  I haven't been able to figure out a way to Get TextColor or any attributes that contains TextColor from the Field data.  I am sure it exists somewhere.  I just can't seem to find it.

       

      With my humble hat in hand, can anyone shed some light on this for me?

       

      Thanks!

      Mark <><

        • 1. Re: Validating "@" Exists in an Email with Show Custom Dialog
          sumaschu

          Just realized I forgot to address the Show Custom Dialog portion of the question.  After correctly identifying a red text field, will use a Show Custom Dialog (which I already know how to use) to draw attention to the red text email field(s) in question.

          • 2. Re: Validating "@" Exists in an Email with Show Custom Dialog
            carlosilvia0

            HI,

            I suggest you change the formula:

             

            PatternCount (Self; ".") = 0

             

            with the following


            Let (

            [

            vsymnbol @ = Position (email; "@"; -1; 1);

            vlength = Length (email)

            ];

                PatternCount (

                  Middle (email; vsymnbol @; vlength);

                ".") - 1

            )

             

             

            With this variant is an error if there are more points after the @.

             

             

            To the second question I'd recommend creating a calculated field that is valued at 1 if the test fails. With a script and using the "find" I can select the relevant records.

             

             

            I hope I can be of help.

            • 3. Re: Validating "@" Exists in an Email with Show Custom Dialog
              electon

              You can retrieve the text color with the GetAsCSS function.

              A red field with text "abcd@" will give you this:

              <span style="color: #FF0000;" >abcd@</span>

               

              So you could use PatternCount to look for this value.

              • 4. Re: Validating "@" Exists in an Email with Show Custom Dialog
                Stephen Huston

                You could just have the script test for the same calc result against the field as is used for setting the formatting, rather than testing for the formatting which results from the calc result.

                • 5. Re: Validating "@" Exists in an Email with Show Custom Dialog
                  sumaschu

                  As always electon, your responses are spot on!  Really appreciate your time and willingness to share.  Thank you so much!

                   

                  Mark <><

                  • 6. Re: Validating "@" Exists in an Email with Show Custom Dialog
                    sumaschu

                    Nice touch carlosilvia0!  I like it alot.

                     

                    Mark <><

                    • 7. Re: Validating "@" Exists in an Email with Show Custom Dialog
                      sumaschu

                      Have run into a snag with this awesome validation piece.  Some of the email addresses I am encountering in the database have more than a single "." in them.  Example: abcd@ef.ghij.com.  Because of the multiple "."s after the "@" sign, am getting a false positive as they turn red, but are actually correct. Spent some time trying to understand the entire sequence of code you so kindly provided so I could change it myself, to no avail.   I really don't understand what the ") - 1 )" at the very end accomplishes. Can you please provide me some guidance on this code triggering when there is not at least one "." after the "@" symbol?  Sorry for the inconvenience.  Appreciate your help!

                       

                      Mark <><

                      • 8. Re: Validating "@" Exists in an Email with Show Custom Dialog
                        beverly

                        Mark, you might consider JavaScript for email validation.

                         

                        1. it may be able to be 'converted' to FM-script/calc

                        or

                        2. it may be able to be run in Web Viewer.

                         

                        beverly

                        • 10. Re: Validating "@" Exists in an Email with Show Custom Dialog
                          Storganise

                          HI Mark,

                           

                          Beverley and user14047 are both offering a good way to solve this, but to answer your question, the -1 part of the Let statement is merely making the calculation what you had it before...

                           

                          PatternCount (Self; ".") = 0

                           

                          Let (

                          [

                          vsymnbol @ = Position (email; "@"; -1; 1);  <<This finds the position of the "@" symbol in the email address

                                                                                                    Position ( text ; SearchString ; Start ; Occurrence )

                          vlength = Length (email)                            <<This finds the length of the email address

                          ];

                              PatternCount (

                                Middle (email; vsymnbol @; vlength);    <<This checks everything from "@" to the end of the email address

                                                                                                    for full-stops. Then takes one away so the result is "0" when

                                                                                                    there is one full-stop ( james@storganise.com ) "1" when there

                                                                                                    are two ( james@edu.mac.com ) etc...

                              ".") - 1

                          )



                          If you want to allow checking for more that one full-stop, then put the PatternCount inside a Case statement and instead of taking the "1" away, check to see if there are more than one full-stops; like this...

                           

                          Let (

                          [

                          vsymnbol @ = Position ( Email ; "@"; -1; 1);

                          vlength = Length (Email )

                          ];

                           

                           

                          Case (

                           

                                    PatternCount ( Middle ( Email ; vsymnbol @ ; vlength ) ; "." ) > 0 and

                                    PatternCount ( Email ; "@" ) =1 ;

                                    TextColor ( Self ; RGB ( 0 ; 0 ; 0 ) ) ;

                                    TextColor ( Self ; RGB ( 255 ; 0 ; 0 ) )

                           

                          )

                          )

                           

                          Hope that helps

                           

                          James

                          • 11. Re: Validating "@" Exists in an Email with Show Custom Dialog
                            taylorsharpe

                            Thanks user14047.  I have used variations of the Brian Dunning validation for years and like it a lot.  Just substitute your field name where it says "TABLE::FILENAME" and you're good to go.  It gives a result of 1 for valid as well as error results.  Or you can just amend it however you want such as to make it truly boolean. 

                             

                             

                             

                            Let (

                                [

                                theEmail = TABLE::FIELDNAME ;

                                _validDomainCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-." ;

                                _invalidLocalCharacters = "!\"#$%&'*,/:;<>?@[\]^`{}|~" ; // from http://www.remote.org/jochen/mail/info/chars.html

                                _theLocalPart = Left ( theEmail ; Position ( theEmail ; "@" ; 1; 1 ) - 1 ) ;

                                _theDomainPart =  Right ( theEmail ; Length ( theEmail ) - Position ( theEmail ; "@" ; 1; 1 )  ) ;

                                _theTopLevelDomain = RightWords ( Substitute ( _theDomainPart ; "." ; " " ) ; 1 ) ;

                                _ValidTopLevelDomains = "AC¶AD¶AE¶AERO¶AF¶AG¶AI¶AL¶AM¶AN¶AO¶AQ¶AR¶ARPA¶AS¶AT¶AU¶AW¶AZ¶BA¶BB¶BD¶BE¶BF¶BG¶BH¶BI¶BIZ¶BJ¶BM¶BN¶BO¶BR¶BS¶BT¶BV¶BW¶BY¶BZ¶CA¶CC¶CD¶CF¶CG¶CH¶CI¶CK¶CL¶CM¶CN¶CO¶COM¶COOP¶CR¶CU¶CV¶CX¶CY¶CZ¶DE¶DJ¶DK¶DM¶DO¶DZ¶EC¶EDU¶EE¶EG¶ER¶ES¶ET¶EU¶FI¶FJ¶FK¶FM¶FO¶FR¶GA¶GB¶GD¶GE¶GF¶GG¶GH¶GI¶GL¶GM¶GN¶GOV¶GP¶GQ¶GR¶GS¶GT¶GU¶GW¶GY¶HK¶HM¶HN¶HR¶HT¶HU¶ID¶IE¶IL¶IM¶IN¶INFO¶INT¶IO¶IQ¶IR¶IS¶IT¶JE¶JM¶JO¶JOBS¶JP¶KE¶KG¶KH¶KI¶KM¶KN¶KR¶KW¶KY¶KZ¶LA¶LB¶LC¶LI¶LK¶LR¶LS¶LT¶LU¶LV¶LY¶MA¶MC¶MD¶MG¶MH¶MIL¶MK¶ML¶MM¶MN¶MO¶MP¶MQ¶MR¶MS¶MT¶MU¶MUSEUM¶MV¶MW¶MX¶MY¶MZ¶NA¶NAME¶NC¶NE¶NET¶NF¶NG¶NI¶NL¶NO¶NP¶NR¶NU¶NZ¶OM¶ORG¶PA¶PE¶PF¶PG¶PH¶PK¶PL¶PM¶PN¶PR¶PRO¶PS¶PT¶PW¶PY¶QA¶RE¶RO¶RU¶RW¶SA¶SB¶SC¶SD¶SE¶SG¶SH¶SI¶SJ¶SK¶SL¶SM¶SN¶SO¶SR¶ST¶SU¶SV¶SY¶SZ¶TC¶TD¶TF¶TG¶TH¶TJ¶TK¶TL¶TM¶TN¶TO¶TP¶TR¶TRAVEL¶TT¶TV¶TW¶TZ¶UA¶UG¶UK¶UM¶US¶UY¶UZ¶VA¶VC¶VE¶VG¶VI¶VN¶VU¶WF¶WS¶YE¶YT¶YU¶ZA¶ZM¶ZW"

                                ] ;

                             

                             

                                Case (

                                    IsEmpty ( theEmail ) ; 1 /*"no value supplied"*/    ;

                                    PatternCount ( theEmail ; "@" ) <> 1 ; "invalid address" ;

                                    PatternCount ( _theDomainPart ; "." ) = 0 ; "invalid formatting" ;

                                    Length ( Filter ( _theLocalPart ; _invalidLocalCharacters ) ) ;

                                        "invalid characters in the local part" ;

                                    Length ( Filter ( _theDomainPart ; _validDomainCharacters ) ) <> Length ( _theDomainPart ) ;

                                        "invalid characters in the domain part" ;

                                    Left ( _theLocalPart ; 1) = "." or

                                        Right ( _theLocalPart ; 1 ) = "." or

                                        Left ( _theDomainPart ; 1 ) = "." or

                                        Right ( _theDomainPart ; 1 ) = "." ;

                                        "invalid formatting" ;

                                   IsEmpty ( FilterValues ( _theTopLevelDomain ; _ValidTopLevelDomains ) ) ; "invalid top level domain" ;

                                   

                                    1

                                )

                            )

                            • 12. Re: Validating "@" Exists in an Email with Show Custom Dialog
                              sumaschu

                              James,

                               

                              Thank you so much!  Works like a charm!

                               

                              Mark <><

                              • 13. Re: Validating "@" Exists in an Email with Show Custom Dialog
                                sumaschu

                                Taylor,

                                 

                                This looks like a very thorough solution!  Question about your Brian Dunning variant:  How often do you find yourself needing to update the list of acceptable extensions?

                                 

                                Thanks,

                                Mark <><

                                • 14. Re: Validating "@" Exists in an Email with Show Custom Dialog
                                  carlosilvia0

                                  Hi, I apologize but I understood only "." after "@". I saw that you use other functions but still you can tell the change: Let ( [ vsymnbol @ = Position (email; "@"; 1; 1); vlength = Length (email) ];     not PatternCount (        Middle (email; vsymnbol @; vlength);     ".") )

                                  1 2 Previous Next