Check Whether string match or not using JQuery

June 07, 2015 0 Comments

If you want to search string from given string then you should use String class. A String class have different methods through them we can search any text from the given Text. In this example, i will take indexOf() method , its a more popular method. Actually This method work when your search characters sequence match with the given text. Now , take a simple example of it.

<%@ Page Language="C#" %>

<!DOCTYPE html>
<html xmlns="">
<head runat="server">
<script src="Scripts/jquery-1.10.2.js"></script>

$(function () {

$('#Button1').click(function () {

if ($('#Text1').val().indexOf('jacob') != -1) {
alert('string match');
return true;

else {

alert('string doesnt match');
return false;



    <form id="form1" runat="server">

    Example of string , exist or not
<input id="Text1" type="text" value="jacob" /><br />
<input id="Button1" type="button" value="button" />

In this example when we press the button,the entered text in the textbox  match with the 'jacob' string which is defined in the index( ) method. If your entered text match then Jquery Return true other wise else. Here '-1' means , null value search.

Jacob Lefore

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google