开发者

simple method that checks text is email with regular expression

开发者 https://www.devze.com 2023-01-02 19:26 出处:网络
Can\'t believe how difficult this seems to be all I want to is to validate a user inout using javascript to make sure that it is an email address. But can\'t get it to work:

Can't believe how difficult this seems to be all I want to is to validate a user inout using javascript to make sure that it is an email address. But can't get it to work:

I am using:

//validates a regulaer expression
Utilities2.prototype.validateEmail = function(stringToValidateArg)
{

    alert('about to check regexp');

    var开发者_运维百科 regExpPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

    alert(regExpPattern.test(stringToValidateArg));

}

But this always returns false, any ideas why is it because of the regular expression?


The regular expression that I'm using is

/([\w-\.\+]+\@[\w-]+\.+[\w]{2,4})/gi

Try this one, should be a bit simpler :)

0

精彩评论

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