-3

It's on the top of my tongue, but I can't remember the method I would use to scan a string variable for something like a specific character. So for example, I want to check IF var emailaddress CONTAINS the '@' symbol. Can anyone give me some help?


Scratch that, indexOf is what I was thinking of.

Tim Post
  • 33,371
  • 15
  • 110
  • 174
Tom Maxwell
  • 9,273
  • 17
  • 55
  • 68

2 Answers2

4

Did you mean indexOf.

var email = 'abc@gmail.com';

if(email.indexOf('@')!=-1){
//doLogic
}
Akhil Sekharan
  • 12,467
  • 7
  • 40
  • 57
-1

in jQuery

jQuery(function($){
//if the input type email contains the @
if( $('input[type="email"]:contains("@")') )
{

alert( $(this).val() ); 

}
else ...

});
Jean G.T
  • 1
  • 10
  • 25