开发者

check if username/email is already exist using javascript

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..


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜