validate email domain in object string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • surferj
    New Member
    • Dec 2008
    • 11

    validate email domain in object string

    Hello,
    I am trying to validate the suffix of an email address for a string entered into a form to ensure it contains the correct domain. Some of the code i am currently using looks like this for blank entries

    if email="" then
    response.redire ct "STS_form.asp?m sg=Please enter your EMAIL!" & querystr
    end if

    but i want to make sure that the email string contains the text "@wellsfargo.co m" and if not then redirect back to the form page.

    So if i were to enter "abc@yahoo. com" i would be redirected back to the form to enter a valid email address. If i entered "abc@wellsfargo .com" then the process would continue to the next if statement.

    I have tried to use the search and match statements with no avail. please help!

    If you need to see more of my code, please let me know.

    Thanks,
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    use regular expression.
    Code:
    var domain_pattern = /@wellsfargo.com$/;
    var email_id = 'your email id';
    alert(domain_pattern.test(email_id));

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by dmjpro
      use regular expression.
      Code:
      var domain_pattern = /@wellsfargo.com$/;
      var email_id = 'your email id';
      alert(domain_pattern.test(email_id));
      You can also do it by using "String.indexOf ". Actually there should be a function like "String.endsWit h" and "String.startsW ith".
      Here you can write own "String.endsWit h" function like ..

      Code:
      String.prototype.endsWith = function(str){
       return this.indexOf(str)==this.length-str.length;
      }

      Comment

      Working...