English 中文(简体)
javascript accreditation for email Format Admission otherwise @abcd.com.gmail, [duplicate]
原标题:javascript validation for email format accepting incorrect email format @abcd.com.gmail, [duplicate]
This question already has answers here:
Closed 11 years ago.

Possible Duplicate:
Validate email address in Javascript?

我必须对电子邮件格式进行验证,我利用下文的CODE来限制特别特征。

onkeypress="return AlphaNumericBox(event,this, @._);"

But now the Problem is I don have any proper validation for the exact format for example its also accepting text like " @abcd.com.gmail,.. " Is there any javascript validation for this? any idea?

提前感谢。

最佳回答
function CheckEmail(address){
    address=address.replace(/(^s*)|(s*$)/g, "");
    var reg=/([w._-])+@([w_-])+(.([w_-])+){1,2}/;
    var matcharr=reg.exec(address);
    if(matcharr!=null){
        if(matcharr[0].length==address.length){
            return true;
        }
        return false;
    }
    return false;
}

eg:
var sVal=" [email protected] ";
var sVal2=" [email protected] ";
console.log(CheckEmail("[email protected]"));    //outpus true
console.log(CheckEmail("@server.com"));   //outpus false
问题回答

我建议你利用这一职能。 我多次测试了它。

function validateEmail (emailAddress) {
        var pattern = new RegExp(/^(("[w-s]+")|([w-]+(?:.[w-]+)*)|("[w-s]+")([w-]+(?:.[w-]+)*))(@((?:[w-]+.)*w[w-]{0,66}).([a-z]{2,6}(?:.[a-z]{2})?)$)|(@[?((25[0-5].|2[0-4][0-9].|1[0-9]{2}.|[0-9]{1,2}.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2}).){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})]?$)/i);
        return pattern.test(emailAddress);
}

现在,你可以轻易地验证任何电子邮件地址:

var isValid = validateEmail( [email protected] ); // returns true;
isValid = validateEmail( @server.com ); // returns false;




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签