Red
Red

Reputation: 6378

Search specified text in text area - jQuery/Javascript

I have a text area with HTML content,now i want to search there for specified text,if text area contains the text i need to return TRUE or FALSE.

also is there any way to check that a specified DOM is on that TEXT AREA [WITH HTML CONTENT] ?

Ex :

<html>
<head>
</head>
<body background="" bgcolor="red">
</body>
</html>

So now i want to check that the BODY tag have Background or bgcolor,if it contains i need to return true,how can i do this ? Actually i am trying to build a UI for editing HTML,if the html area contain

Thank you.

Upvotes: 2

Views: 2954

Answers (2)

Anatoly
Anatoly

Reputation: 15530

You can use indexOf, see the following example here: http://jsfiddle.net/mikhailov/S5jaz/2/

html

<textarea id="txt">
  Here I am
</textarea>

JS

var txt = $('#txt').val();
var word1 = txt.indexOf('Heref') != -1;    // false
var word2 = txt.indexOf('Here I') != -1;   // true

Upvotes: 0

Tules
Tules

Reputation: 4915

var text = $('#textarea').val();
var regex = /.../;
var found = text.match(regex);
if (found != null){return 1}

Upvotes: 1

Related Questions