Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2016
    Posts
    14
    Provided Answers: 1

    Unanswered: Inputbox code request

    this is a part of a VBA code to send mails using CDO and i'm using inputbox to enter mail address only like this


    PHP Code:
      Dim Mailto  As String          
         Mailto 
    InputBox("Enter Mail Address""Enter Email Address")

        If 
    Mailto <> "" Then 
             MsgBox 
    ("Mail Will sent to " Mailto " please wait  "), vbMsgBoxRtlReading"Sending ..."
        
    Else
             
    MsgBox "message not sent , try again"vbCritical"Error"
        
    End If 
    i want to make it as input mask like mail : xxxx@xxx.xxx
    and i don't want the inputbox to accept this data on it until it match MASK

    how to code it ???

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    email id's are problematical
    to start with if you restrict a valid email to be
    xxxx@xxx.xxx
    you will have problems

    the domain can be multi qualified
    eg @yahoo.co.uk
    the recipient can also be qualified
    forename.surname

    so all you can really check is that their is a @ followed by some letters or numbers, a full stop followed by more letters
    https://support.office.com/en-gb/art...5-3c929314bd33

    https://en.wikipedia.org/wiki/Email_address
    suggests that the the recipient can be upto 64 characters and the overall address no more that 254 characters

    the wiki also refers to other forms of checking that you may want to implement, but if you do it will be best done in a function
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jul 2016
    Posts
    14
    Provided Answers: 1
    Quote Originally Posted by healdem View Post
    email id's are problematical
    to start with if you restrict a valid email to be

    you will have problems

    the domain can be multi qualified
    eg @yahoo.co.uk
    the recipient can also be qualified
    forename.surname

    so all you can really check is that their is a @ followed by some letters or numbers, a full stop followed by more letters
    https://support.office.com/en-gb/art...5-3c929314bd33

    https://en.wikipedia.org/wiki/Email_address
    suggests that the the recipient can be upto 64 characters and the overall address no more that 254 characters

    the wiki also refers to other forms of checking that you may want to implement, but if you do it will be best done in a function
    thanks for replay
    and i don't mean to do it as mask exactly
    i know mask take a specific digits.


    let's say it will be a specific mail domain like

    xxx@dbforums.com
    xxxxx@dbforums.com
    xx@dbforums.com

    ????

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    ...which are valid
    as is alvin.genius@mydomain.org.fr
    but NOTE that although mydomain.org.fr looks legit it doens't neccesarily mean that mydomain.org.fr exists. all it means is that mydomain.org.fr passes the rules for what constitutes a domain
    even if mydomain.org.fr does exist there is no way of validating that alvin.genius@mydomain.org.fr is legit, short of sending a test email and verifying there is a response or no rejection email. but not every domain sends a rejection eam il immediately if any

    read the office reference above

    if you know the domain must be a specific value then match for it
    push it into a function, which could be something like:-

    Code:
    public function ValidateEmail(emaild as string, optional RequiredDomain as string = "") as boolean
    ValidateEmail = vbfalse 'set up our default return value
    dim SymbolPosition as integer
    'what to check..... well you could read the relevant RFC's on what constitutes valid symbols in an email address
    'at the very least it must be 5 characters long
    if isNULL(emailid) = vbtrue or len(emailid)<=4 then
      exit function
    endif
    
    'it must have a @ symbol somewhere in the middle
    SymbolPosition = instr(emaild,"@")
    if symbolposition <=1 or symbolposition = len(emailid) then
      exit function
    endif
    
    'if RequiredDomain is set then that MUST appear int he email address
    'Note the shortest domain(afaik IS X.YY) however its highly unlikely you find one in the wild
    if len(RequiredDomain) > 4 then 'set then that MUST appear in the email address AFTER the @
      if (requireddomain <> mid(emailid,symbolposition) then  
        exit function
      endif
    endif
    
    'Note the shortest domain(afaik IS X.YY) however its highly unlikely you find one in the wild
    if len(emailid) = symbolposition <4) then
      exit function
    endif
    
    'there must be a fullstop AFTER the @ symbol 
    if instr(symbolposition,emailid,".") <= symbolposition +2 then
      exit function
    endif
    
    'after that
    'well there is a RFC detailing what symbols are valid you coudl check for those
    'in the absence of any other tests we have to presume the email is OK, but we dont' know if its truly valid until we send an email and we have proof it was recieved
    'we can validatre an email id so that we think its meets the relevant standard, but that doens't mean it actualkly exists
    ValidateEmail = vbtrue
    end function
    note the above is 'air code' IE its been made up on the fly and may well contain logic errors, typos and other problems. it may well require debugging and will require proving that it does actually work before using.

    call it using = ValidateEmail(anEamilAddress)
    or ValidateEmail(anEamilAddress,"dbforums.com")
    and so on
    Last edited by healdem; 07-14-16 at 07:37.
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •