Reputation: 2902
I am validating a form following is my code JQuery:
var x = $('.email').val() //fetching the value of input box
Regex:
function validateEmail(email) {
var emailReg = 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);
var valid = emailReg.test(email);
if (!valid) {
return false;
} else {
return true;
}
}
although this function will validate my email, but I want to show a message if user is putting @ and . together. all I want to check if two characters are coming together... i mean like this
so I need a condition in which I can get to know whether both are together or not...please help :)
Upvotes: 0
Views: 93
Reputation: 15913
use can use .match()
as
var str="[email protected]";
var n=str.match(/@\./g);
it will find @. and then run if found
if(n)
// code
Upvotes: 0