Wednesday, 21 March 2012

JavaScript Email Validation through Regular Expression

function ValidateEmail(str){    
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;        
    return emailPattern.test(str);   
}

Tuesday, 13 March 2012

JavaScript Replace all match string through Regular Expression


function ReplaceAll(txt, replace, with_this) {
    return txt.replace(new RegExp(replace, 'g'), with_this);
}