简体   繁体   English

使用javascript检查用户名/电子邮件是否已经存在

[英]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.. 请帮助我.. :-(非常感谢你们..

将该表单发回时,可以在页面下面的PHP脚本中执行此检查,或者如果不需要重新加载页面就可以进行AJAX检查-尽管即使使用后一种方法,您也必须执行检查后端,或冒一些恶意用户绕过JavaScript并输入重复条目的风险。

You will need ajax to check if a username has been taken. 您将需要ajax来检查是否使用了用户名。

Ajax is sending and receiving data without refreshing the page. Ajax在不刷新页面的情况下发送和接收数据。

here is a simple tutorial: http://www.w3schools.com/Ajax/ajax_example.asp 这是一个简单的教程: http : //www.w3schools.com/Ajax/ajax_example.asp

I suggest you use a javascript library like jQuery to make everything easier. 我建议您使用jQuery之类的JavaScript库来简化一切。

如果您熟悉jQuery,请查看支持远程处理的验证插件 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM