Click here to Skip to main content
14,971,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.
I want implement like operator in javascript.

eg. myString = "Mumbai"

If user gives input "Mu" it must match.
It similar to 'like' operator from Sql.

Can somebody provide a solution for me?
Posted
Updated 29-Aug-12 3:08am
v2

1 solution

You can use regular expressions in Javascript to do pattern matching of strings.

For example:
JavaScript
var s = "Mumbai";
if (s.match(/Mu.*/)) {
  // do something
}



--Amit
   
v3
Comments
__TR__ 29-Aug-12 8:55am
   
5+
_Amy 29-Aug-12 9:32am
   
Thank you. :)
Rock4J 17-Aug-15 22:50pm
   
how to use variable inside the MATCH to compare between two variable ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900