Results 1 to 14 of 14

Thread: [RESOLVED] Updating User Info with validation of unique email address.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    97

    Resolved [RESOLVED] Updating User Info with validation of unique email address.

    Hi everyone

    I have already done from register.aspx and works fine but I want to validate updated email to avoid any dulicated email.

    can anyone help to do that?

    bintaleb

  2. #2
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Updating User Info with validation of unique email address.

    Hello,

    Are you using the built in Membership Providers? I reason that I ask this question all the time, and advocate the use of them, is because what you are asking for (i.e. preventing duplicate emails) has already been thought about, and implemented within the provider model.

    Gary

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    97

    Re: Updating User Info with validation of unique email address.

    Hello Gary
    thank you for quick response
    Yes I have already used membership Providers in my project and I have prevented any new user to type duplicate email but let me clear my question.

    regarding register.asp I have already done as mentioned, after that I create new page to allow user to change his email by using two textboxs control to confirm new email but I could not find method or property to validate if updated email is already exist or not, I can do that by using stored procedure but I don't because I believe there is a way to do that by membership provider but unfortunately I don't know.

    note: in web.config I set RequiresUniqueEmail is true and works fine with me in createuserwizard.

    bintaleb

  4. #4
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,605

    Re: Updating User Info with validation of unique email address.

    You could check with Membership.GetUserNameByEmail().
    If the email the user enters does not return a current user then you are good to go.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  5. #5
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Updating User Info with validation of unique email address.

    Ah, I see what you are getting at. Sorry for missing that!

    As per the documentation, here:

    http://msdn.microsoft.com/en-us/libr...iqueemail.aspx

    RequiresUniqueEmail is only inspected at the time the new user is created. Afterwards, it will be up to you to ensure that each email address remains unique. As sap has mentioned, you could use that method, or there is also FindUsersByEmail:

    http://msdn.microsoft.com/en-us/library/9c7by5c5.aspx

    Gary

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    97

    Re: Updating User Info with validation of unique email address.

    thanks sap and gary

    now it is working good.

  7. #7
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] Updating User Info with validation of unique email address.

    Hello,

    For the benefit of the community, you might like to post the code that you have used.

    Gary

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    97

    Re: [RESOLVED] Updating User Info with validation of unique email address.

    Quote Originally Posted by gep13 View Post
    Hello,

    For the benefit of the community, you might like to post the code that you have used.

    Gary

    Hello Gary

    here is what I have used to check a new email is already exist or not.

    Code:
    Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpdate.Click
    Dim CheckUserUser As String = Membership.GetUserNameByEmail(txtEmail.Text.Trim)
    IF CheckUserUser <> Nothing Then
    lblErrormsg.text = "Email is alraedy exist."
    Else  
      Dim myObject As MembershipUser = Membership.GetUser()
      myObject.Email = txtEmail.Text.Trim
      Membership.UpdateUser(myObject)
      lblErrormsg.text = "your Email has been updated successfully."
    End If
    but I am thinking to use custom validator to dispaly error message, is that possible?

  9. #9
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] Updating User Info with validation of unique email address.

    Hello,

    You could use a custom validator, yes. You wouldn't easily be able to add client side validation, not unless you wanted to go to the length of creating a WebMethod that you could call from the client side. Not impossible, but a bit of work. Might be easier just to stick with what you have.

    Gary

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    97

    Re: [RESOLVED] Updating User Info with validation of unique email address.

    thank you so much.

  11. #11
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] Updating User Info with validation of unique email address.

    Quote Originally Posted by bintaleb View Post
    thank you so much.
    Not a problem at all, happy to help where I can.

  12. #12
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,605

    Re: [RESOLVED] Updating User Info with validation of unique email address.

    You could(should) also add a validation of a correct email formatting on the client side.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  13. #13
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] Updating User Info with validation of unique email address.

    Quote Originally Posted by sapator View Post
    You could(should) also add a validation of a correct email formatting on the client side.
    Agreed, you could add a client side validation to check the validity of the format of the email address with the use of a Regular Expression, but that obviously wouldn't tell you whether that email address was already in use or not.

    Gary

  14. #14
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] Updating User Info with validation of unique email address.

    Hello there,

    The following webpage just came through on my RSS stream, and I immediately thought of this thread:

    http://www.4guysfromrolla.com/articles/022311-1.aspx

    Hope it helps!

    Gary

Posting Permissions

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



Click Here to Expand Forum to Full Width