tags:

views:

143

answers:

3

hi there, i have a simple question.

how can i check if the username or email they entered is already exist..

i have this code,

        if(document.RegForm.user.value =="")
        {
        alert("User Name Please?");
        valid=false;
        }

that's my code for username, i don't know what code i will add to check if user name is already exist.. :-(

hmm.. also this is for the email:

        var emailExp= /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
        strEmail=document.RegForm.eadd.value;

    if(strEmail.search(emailExp)==-1)
        {
        alert("A Valid Email Address Required");
        valid=false;
        }

what code will i add? to check if email is already exist. help me please .. :-( thank you so much guys..

+1  A: 

Either perform this check in the PHP script underlying the page, when the form is posted back, or look into AJAX if this is something that you need to do without reloading the page - although even with the latter approach you'd have to perform the check on the back-end or risk some malicious user bypassing the javascript and pushing in a duplicate entry.

Will A
A: 

You will need ajax to check if a username has been taken.

Ajax is sending and receiving data without refreshing the page.

here is a simple tutorial: http://www.w3schools.com/Ajax/ajax_example.asp

I suggest you use a javascript library like jQuery to make everything easier.

Keyo
oh thank you very much..
mayumi
No problem. I think you should definitely do some reading on what ajax is and how to use it with jQuery. It will come in useful time and time again.For your server side code you will need to make a page (not in html) that spits out something easy to read with javascript. You can use plain text and print out 'true' if the username is available and 'false' if it is not.If you go with jQuery this might be a good tutorial: http://articles.sitepoint.com/article/ajax-jquery
Keyo
hmm..ok thank you so much.. it is really a big help. :)
mayumi
A: 

If you are familiar with jQuery, check out the validation plug-in, which supports remoting :)

yan.kun