Bharat Soni
Bharat Soni

Reputation: 2902

check if two specific characters are together

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

[email protected]

so I need a condition in which I can get to know whether both are together or not...please help :)

Upvotes: 0

Views: 93

Answers (2)

Tushar Gupta
Tushar Gupta

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

Anton
Anton

Reputation: 32581

Try this, put it in the if statement

email.indexOf('@.') == -1

Upvotes: 2

Related Questions