5 Replies Latest reply on Nov 30, 2015 7:21 AM by g4guitar

    How can I make sure a field contains certain criteria? E.g. Email field needs an @ and at least one dot.

    g4guitar

      Thank you.

        • 1. Re: How can I make sure a field contains certain criteria? E.g. Email field needs an @ and at least one dot.
          taylorsharpe

          Here is what I use to validate emails:

           

           

          Let (

              [

              theEmail = EmailField ;

              _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

              )

          )

           

           

           

           

          /*

          Name:

          EmailIsValid

           

           

          History:

          Created by Paul Turnbull

          Creation Date: 13-10-2005

          Modified Date: 13-11-2005 paul@fourofus.ca - fixed numerous bugs.

           

           

          Purpose: Returns True if the email supplied is valid an error message if it is not.

           

           

          Parameters:

          theEmail

           

           

          Important Notes:

          List of TLDs from http://data.iana.org/TLD/tlds-alpha-by-domain.txt

          Will not handle urls in the form contact@domain.com/some.name although you could edit to handle this if you like.

          */

          • 2. Re: How can I make sure a field contains certain criteria? E.g. Email field needs an @ and at least one dot.
            taylorsharpe

            Technically I jumped to a conclusion you wanted to validate email. 

             

            But the validation calculation to see if an "@" exists in a field is:

             

            PatternCount ( Field_Name ; "@" )

            • 3. Re: How can I make sure a field contains certain criteria? E.g. Email field needs an @ and at least one dot.
              g4guitar

              Thank you Taylor,

               

              That's brilliant. The second option is all I need for now but the first option is good to know for future reference.

               

              One more question, if I clear the field later (making it empty) it still prompts as it expects the @ mark. Is there a way to also accept an empty field?

               

              Thank you again.

              • 4. Re: How can I make sure a field contains certain criteria? E.g. Email field needs an @ and at least one dot.
                Nehme

                This is what I put in the email field auto-enter calculation:

                 

                 

                 

                Let (

                 

                 

                [

                email = TextFormatRemove ( Substitute( Trim ( Self ) ;"¶";"")) 

                ]

                ;

                 

                 

                Case (

                 

                 

                PatternCount ( email ; "@") = 0 or

                PatternCount ( email ; ".") = 0

                or PatternCount ( email ; " ") > 0

                ;

                 

                 

                TextColor ( email ; RGB ( 255;0;0 ) );

                 

                 

                TextColor ( email ; RGB ( 0;0;0 ) )

                 

                 

                )

                )

                 

                In this way, I will have a red flag only and not prevent the user from entering other values (because there are some emails that might contain @ twice for example