Possible Duplicate:
Emulating SQL LIKE in JavaScript
Is there an operator in JavaScript which is similar to the like
operator in SQL? Explanations and examples are appreciated.
Possible Duplicate:
Emulating SQL LIKE in JavaScript
Is there an operator in JavaScript which is similar to the like
operator in SQL? Explanations and examples are appreciated.
You can use regular expressions in Javascript to do pattern matching of strings.
For example:
var s = "hello world!";
if (s.match(/hello.*/)) {
// do something
}
The match()
test is much like WHERE s LIKE 'hello%'
in SQL.
No.
You want to use: .indexOf("foo")
and then check the index. If it's >= 0, it contains that string.
Use the string objects Match method:
// Match a string that ends with abc, similar to LIKE '%abc'
if (theString.match(/^.*abc$/))
{
/*Match found */
}
// Match a string that starts with abc, similar to LIKE 'abc%'
if (theString.match(/^abc.*$/))
{
/*Match found */
}
No there isn't, but you can check out indexOf as a starting point to developing your own, and/or look into regular expressions. It would be a good idea to familiarise yourself with the JavaScript string functions.
EDIT: This has been answered before:
No, there isn't any.
The list of comparison operators are listed here.
For your requirement the best option would be regular expressions.