Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

jQuery Check if String Contains Specific Word in JavaScript

Sep 12, 2013
Introduction

Here I will explain how to use
jQuery to check particular word in string in JavaScript or jQuery to check if string contains specific word in JavaScript.

Description:
  
In previous articles I explained jQuery add border to images in webpage, jQuery show loading image in pageload, jQuery hide div elements after 5 seconds, jQuery convert am / pm time to 24 hours time, jQuery print div content with css
and many articles relating to JQuery, JavaScript. Now I will explain how to check if string contains specific word in JavaScript.

To check particular word in string we need to write code like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Check Particular word in string in JavaScript</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function() {
$('#btnCheck').click(function() {
var str = 'how are you';
var txt = $('#txtword').val();
if (str.indexOf(txt) > -1) {
alert('String Contains Word');
return true;
} else {
alert('String Does not contains word');
return false;
}
});
})
</script>
</head>
<body>
<div>
Check word in this String: <b>How are You</b><br />
Enter Text to Search: <input type="text" id="txtword" value="how" />
<input type="button" id="btnCheck" value="Check" />
</div>
</body>
</html>
Live Demo

Check word in this String: How are You

Enter Text to Search:


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

4 comments :

Anonymous said...

Dear sir,
What is the SMTP Server Name & Port Number for Yahoo.
please sir i requested to u ......plz plz tell me this one....)

I Used
SMTP Server Name :smtp.mail.yahoo.com
Port Number:

My program is showing send mail but actually mail is not send......):

ranadheerrannu said...

* Incoming Mail Server (POP3): plus.pop.mail.yahoo.com
Use SSL, port: 995
* Outgoing Mail Server (SMTP): plus.smtp.mail.yahoo.com
Use SSL, port: 465, use authentication

i found it here: http://answers.yahoo.com/question/index?qid=20080628194548AA0yNUg

Pwna|d said...

This doesn't really have anything to do with jQuery...

Anonymous said...

thank you

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.