Search

Sunday, June 7, 2015
0 comments

Check Whether string match or not using JQuery

1:04 AMSunday, June 7, 2015
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="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
<script src="Scripts/jquery-1.10.2.js"></script>

<script>
$(function () {

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

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

else {

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


});

})

</script>
</head>
<body>
    <form id="form1" runat="server">

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

    </form>
</body>
</html>
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.
Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top