2

If input text field contains "@twitter.com", would like to append text to div.

Currently have the following but only works when [email protected], any suggestions?

var test = jQuery('input[name$="user_email"]').val(); 
  if(test == "@twitter.com"){
     jQuery(".iump-clear").append('<div>Please update your email address</div>');
  }

<input type="text" name="user_email" value="[email protected]">
<div class="iump-clear"></div>

1 Answer 1

2

You should check if @twitter.com is contained in input, you can use .indexOf() for that

var test = jQuery('input[name$="user_email"]').val(); 
  if(test.indexOf("@twitter.com")>-1){
     jQuery(".iump-clear").append('<div>Please update your email address</div>');
  }

<input type="text" name="user_email" value="[email protected]">
<div class="iump-clear"></div>
Sign up to request clarification or add additional context in comments.

2 Comments

That worked! I wasn't familiar with indexOf(), thanks a lot!
Or using a Regex: /@twitter.com$/i.test(test)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.