RegExp taking too much in checking emailid

I am checking for a value, whether it is emailid or not using below code.

function getEmailId(inputTxt){
    var email = /^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/;
    return new RegExp(email).test(inputTxt);
}


var sTime = new Date();
var a = getEmailId("kuldeep.sharma@daffodilsw.com-daffodilsw");

console.log("value>>>>"+a+">>>time>>>>"+(new Date()-sTime));

for this it takes almost 55 sec. to give result, if I change

var a = getEmailId("rajit.garg@daffodilsw.com-daffodilsw");

for this it takes almost 3.5 sec to give result

I am not able to understands this behaviour,

Can anyone please help me to understands this behaviour and is there any way possible to get the result instantly…


Source: regex

Leave a Reply