[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
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
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
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.
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
Re: Updating User Info with validation of unique email address.
thanks sap and gary
now it is working good.
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
Re: [RESOLVED] Updating User Info with validation of unique email address.
Quote:
Originally Posted by
gep13
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?
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
Re: [RESOLVED] Updating User Info with validation of unique email address.
Re: [RESOLVED] Updating User Info with validation of unique email address.
Quote:
Originally Posted by
bintaleb
thank you so much.
Not a problem at all, happy to help where I can.
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.
Re: [RESOLVED] Updating User Info with validation of unique email address.
Quote:
Originally Posted by
sapator
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
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